使用
rails 4.0.2和 activeadmin 1.0
模特:
class Tag < ActiveRecord::Base
translates :url, :alt_tag, :h1, :content, :name, :nav_content, :meta_desc, :meta_title
has_many :tag_translations
accepts_nested_attributes_for :tag_translations, allow_destroy: true
end
class class TagTranslation < ActiveRecord::Base
belongs_to :tag
validates_uniqueness_of :locale, :scope => :tag_id
end
activeadmin
ActiveAdmin.register Tag do
def permitted_params
params.permit tag: [:name, :active_general, :active_general_breakfasts, :active_general_apartments,
:active_article, :country_id, :region_id, :active_country_houses, :active_country_appartments,
:active_country, :meta_desc, :meta_title, :active_house, :active_apartment, :tag_list,
:nav_content, :alt_tag, :h1, :content, :name, tag_translations_attributes: [:id, :tag_id, :locale,
:alt_tag, :h1, :content, :name, :nav_content, :meta_desc, :meta_title, :_destroy, :_create, :_update,:_update]]
end
end
我在日志文件中收到此错误消息。我在这做错了什么?
WARNING: Can't mass-assign protected attributes for Tag: country_id, region_id, active_house, active_apartment, active_general, active_general_apartments, active_general_breakfasts, active_article, name, h1, content, alt_tag, nav_content, url, meta_desc, meta_title
WARNING: Can't mass-assign protected attributes for Tag::Translation: locale
thanks..remco
答案 0 :(得分:1)
ActiveAdmin.register Tag do
permit_params :name, :active_general, :active_general_breakfasts, :active_general_apartments,
:active_article, :country_id, :region_id, :active_country_houses, :active_country_appartments,
:active_country, :meta_desc, :meta_title, :active_house, :active_apartment, :tag_list,
:nav_content, :alt_tag, :h1, :content, :name, tag_translations_attributes: [:id, :tag_id, :locale,
:alt_tag, :h1, :content, :name, :nav_content, :meta_desc, :meta_title, :_destroy, :_create, :_update,:_update]
end