ruby on rails - "Can't mass-assign protected attributes" error, even they exists in attr_accessible -
i have table, created database migration:
class createtickets < activerecord::migration def create_table :tickets, :primary_key => :tickets_id |t| t.string :title, null: false t.text :body t.datetime :create_date t.integer :author_id t.integer :status, null: false, default: 0 end end a model:
class ticket < activerecord::base attr_accessible :title, :body, :create_date, :author_id, :status end and when try create record:
user.create(title: title,body: body,create_date: time.zone.now, author_id: @author_id,status: 0) i error:
can't mass-assign protected attributes: title, body, create_date, author_id, status
what did wrong?
you're trying create user instead of creating ticket.
change code to:
ticket.create(title: title, body: body, create_date: time.zone.now, author_id @author_id, status: 0) hope, it'll help.
Comments
Post a Comment