我是全新的 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
链接这两个模型的问题吗?如果我使用它没问题,那么我应该怎么做才能让创建/更新工作?