【问题标题】:Can't mass-assign protected attributes in Activeadmin无法在 Activeadmin 中批量分配受保护的属性
【发布时间】:2014-09-19 13:59:56
【问题描述】:

使用

rails 4.0.2 和 活跃管理员 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.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

谢谢..remco

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-4 activeadmin


    【解决方案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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-04
      • 1970-01-01
      • 2012-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多