我是一个铁杆菜鸟,所以下面可能是缺乏理解,但我一直在寻找/阅读整天,似乎无法找到解决方案.
我有两个模型 – 项目和技术:
项目:
class Project < ActiveRecord::Base attr_accessible description,:name has_and_belongs_to_many :technologies,:join_table => :projects_technologies end
技术:
class Technology < ActiveRecord::Base attr_accessible :abbr,:description,:name has_and_belongs_to_many :projects,:join_table => :projects_technologies end
我的Create_Projects_Technologies迁移如下:
class CreateProjectsTechnologies < ActiveRecord::Migration def self.up create_table :projects_technologies,:id => false do |t| t.references :project t.references :technology end add_index :projects_technologies,[:project_id,:technology_id] add_index :projects_technologies,[:technology_id,:project_id] end def self.down drop_table :projects_technologies end end
然后,我使用Active Admin使用以下格式创建和编辑项目模型:
ActiveAdmin.register Project do form do |f| f.inputs "Project attributes" do f.input :name f.input :description f.input :technologies,as: :check_Boxes end f.buttons end end
这正确地将我的所有技术显示为复选框,但是一旦我提交表单,我就会遇到以下错误,我无法克服:
ActiveModel :: MassAssignmentSecurity :: Admin :: ProjectsController#update中的错误
Can't mass-assign protected attributes: technology_ids
所有的帮助非常感谢:D
解决方法
简单地将technology_id添加到Project attr_accessible
attr_accessible :client,:name,:technology_ids
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。