Creating HABTM Rails 3 using Active Admin raises the error "Prevent bulk assignment of protected attributes:"

I am rails noob, so below, perhaps, to a lack of understanding, but I kept looking / reading and could not find a solution.

I have two models - project and technology:

Project:

class Project < ActiveRecord::Base

  attr_accessible description, :name

  has_and_belongs_to_many :technologies, :join_table => :projects_technologies

end

Technology:

class Technology < ActiveRecord::Base

  attr_accessible :abbr, :description, :name

  has_and_belongs_to_many :projects, :join_table => :projects_technologies

end

The migration of My Create_Projects_Technologies was as follows:

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

Then I use Active Admin to create and edit project models using the following form:

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

This correctly shows all my technologies as checkboxes, but as soon as I submit the form, I find the following error that I could not overcome:

ActiveModel :: MassAssignmentSecurity :: Error in Admin :: ProjectsController # update

Can't mass-assign protected attributes: technology_ids

All help is much appreciated: D

+5
1

add technology_ids Project attr_accessible

attr_accessible :client, :description, :name, :technology_ids
+7

All Articles