ruby-on-rails – 使用Active Admin创建Rails 3 HABTM会抛出’无法大量分配受保护的属性:’错误

我是一个铁杆菜鸟,所以下面可能是缺乏理解,但我一直在寻找/阅读整天,似乎无法找到解决方案.

我有两个模型 – 项目和技术:

项目:

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

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...