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_createupdate_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 回答