i18n-active_record和protected_attributes

时间:2014-11-29 20:09:22

标签: ruby-on-rails rails-i18n

当我尝试添加新翻译时:

I18n::Backend::ActiveRecord.new.store_translations(:encoding, :key => value)

我有以下错误:

ActiveModel::MassAssignmentSecurity::Error: Can't mass-assign protected attributes for I18n::Backend::ActiveRecord::Translation: locale, key, value

有人知道如何解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

我补丁问题:

module TranslationPatch
  extend ActiveSupport::Concern
  included do
    if defined?(ProtectedAttributes)
      attr_accessible :missing,:locale,:key,:value
    end
  end
end

并将其包含在locale.rb文件中:

require 'i18n/backend/active_record'
I18n.backend = I18n::Backend::ActiveRecord.new

I18n::Backend::ActiveRecord::Translation.send(:include,TranslationPatch)