what i need to made to make the create action works?
i hava a table with a has_and_belongs_to_many association. The "new" page works fine, but when i select itens and try to save it raises an error:
Can't mass-assign protected attributes: book_id
I tryed to set:
config.active_record.whitelist_attributes = false
but it didnt change anything
My model:
class Book < ActiveRecord::Base
has_and_belongs_to_many :orbs
attr_accessible :dataf, :datai, :descr, :nome
validates :nome, uniqueness: true, presence: true
end
class Orb < ActiveRecord::Base
belongs_to :orb_type
has_and_belongs_to_many :books
attr_accessible :descr, :nome, :orb_type_id
validates :nome, uniqueness: true, presence: true
end
My controler:
def create
@orb = Orb.new(params[:orb])
respond_to do |format|
if @orb.save
format.html { redirect_to @orb, notice: 'Orb was successfully created.' }
format.json { render json: @orb, status: :created, location: @orb }
else
format.html { render action: "new" }
format.json { render json: @orb.errors, status: :unprocessable_entity }
end
end
end
Also, anyone can tell me what i will have to do to make the autoboxes beeing checked when o press "edit" i am new to rails. Thx!
Edit: adding attr_accessible :book_id to my orb model raise the error:
unknown attribute: book_id
It worked on the console with << operation.