2012-04-06 4 views
0

コンテンツを翻訳したモデルをglobalize3で更新しようとしています。これを行うには、モデルを更新するためにロケールを複数回変更する必要があります。しかし、update_attributesメソッドはブロックをパラメータとして受け入れていないようです。次のことを達成する他の方法はありますか?Railsのブロック内の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 

私はupdate_attributes続いfirst_or_createをやっている理由は、私は私のシードファイルを複数回実行し、データが適宜更新持つことができるようにしたいということです。

答えて

1

G3は、優れたあるMik、おかげでset_translations方法なので、あなたがすることができます

Country.where(code: 'NLD').first_or_create.set_translations(
    :en => { :name => 'Netherlands, The' }, 
    :nl => { :name => 'Nederland' } 
) 
+0

を持っています! – Laurens

関連する問題