当我尝试添加新翻译时:
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
有人知道如何解决这个问题吗?
答案 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)