2012-08-16 53 views
0

我在執行rake:seed時遇到此錯誤。不能大規模指派保護屬性如何將attr_accessible添加到schema.rb中的數據庫表中

我知道,他們是這個錯誤的其他職位和解決的辦法是attr_accessible添加到模型中,但我不知道如何將它添加在ActiveRecord::Schema.define

其實我從書中務實的書,我從該書這個m代碼的學習軌道,

ActiveRecord::Schema.define(:version => 20120814110309) do 

    create_table "products", :force => true do |t| 
    t.string "title" 
    t.text  "descripton" 
    t.string "image_url" 
    t.decimal "price",  :precision => 8, :scale => 2 
    t.datetime "created_at",        :null => false 
    t.datetime "updated_at",        :null => false 
    end 

end 

我添加attr_accessible來描述,所以我怎麼做,

UPDATE:

我的products.rb已經attr_accessible了,但它不工作!?

# app/models/product.rb 
class Product < ActiveRecord::Base 
    attr_accessible :descripton, :image_url, :price, :title 
end 

UPDATE:

*我想通了,這是一個錯字的問題,感謝名單,無論如何,它的工作,但我didntget是在scema加入attr_accessable而在模型中加入它的實際解決方案。如果這不是一個好主意,爲什麼呢?*

回答

1

attr_accessible doens't go on schema.rb。它依賴於你的模型。根據您發佈你上面的代碼可能想:

# app/models/product.rb 
class Product < ActiveRecord::Base 
attr_accessible :title, :description # Add as needed 
end 
+0

雅,將工作,謝謝,我知道它會工作,但我在想,如果我可以從架構添加它,感謝反正 – pahnin 2012-08-16 21:11:14

+0

我剛剛發現我的product.rb已經有了! – pahnin 2012-08-16 21:25:29

+0

它在你的產品中,你仍然得到質量分配的錯誤?如果是這樣,發佈您的product.rb代碼,我會看看。 – 2012-08-17 23:17:54

相關問題