0

を通じてコン​​テンツを翻訳したモデルを更新しようとしていglobalize3ます。そのためには、ロケールを何度も変更してモデルを更新する必要があります。ただし、update_attributesメソッドはブロックをパラメーターとして受け入れないようです。以下を達成する他の方法はありますか?

Country.where(code: 'NLD').first_or_create.update_attributes do |country|
  I18n.locale = :en
  nld.name = 'Netherlands, The'

  I18n.locale = :nl
  nld.name = 'Nederland'
end

私がやっている理由は、シードファイルを複数回実行し、first_or_createそれupdate_attributesに応じてデータを更新できるようにしたいからです。

4

1 に答える 1

1

G3にはset_translationsメソッドがあるので、できます

Country.where(code: 'NLD').first_or_create.set_translations(
  :en => { :name => 'Netherlands, The' },
  :nl => { :name => 'Nederland' }
)
于 2012-04-06T08:14:17.687 に答える