我品牌spankin' - 新軌,所以請原諒我,如果這是一個愚蠢的問題 - 我根本無法拼湊出足夠的答案告訴我們,如果我開始不正確。開始。Rails的腳手架參考不會保存,由於大規模分配限制
我創造了一切與我
Company
模型rails g scaffold Company name:string description:text location_city:string location_state:string accounttype:references
我創建因此相關
Accounttype
模型rails g scaffold Accounttype id:primary_key name:string price:decimal
我
Company
模型中的任何包含以下準備:belongs_to :accounttype
attr_accessible :description, :location_city, :location_state, :name
,當我去了公司,我的支架產生編輯表單,並在這些字段中輸入數據時,它拋出一個錯誤:
Can't mass-assign protected attributes: accounttype
如果我添加
:accounttype
到attr_accessible
,它拋出Accounttype(#70175254242100) expected, got String(#70175215042700)
用下面的請求參數:{"utf8"=>"✓", "authenticity_token"=>"oXm3cqo0jemKYFB5OGqn5ixXLSB+bH19/1RhPUu0ZHU=", "company"=>{"name"=>"Acme Corp", "description"=>"a", "location_city"=>"san diego", "location_state"=>"california", "accounttype"=>"1"}, "commit"=>"Create Company"}
那麼,我的問題是我用:references
來鏈接這兩個模型?如果那是我用過的,那麼我應該怎麼做才能創建/更新才能工作?
謝謝你傑森的完整的答案。但是,即使進行了這些更改,它仍然會拋出相同的錯誤:'不能批量分配受保護的屬性:accounttype' – Kristian