我有一個表,從一個數據庫遷移創建:「不能大規模指派保護屬性」的錯誤,即使它們存在於attr_accessible
class CreateTickets < ActiveRecord::Migration
def up
create_table :tickets, :primary_key => :tickets_id do |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
模型:
class Ticket < ActiveRecord::Base
attr_accessible :title, :body, :create_date, :author_id, :status
end
當我試圖創造一項紀錄:
User.create(title: title,body: body,create_date: Time.zone.now, author_id: @author_id,status: 0)
我得到這個錯誤:
Can't mass-assign protected attributes: title, body, create_date, author_id, status
我做錯了什麼?
是的,它可以幫助,謝謝... 太愚蠢錯誤... –