【发布时间】:2016-11-23 16:42:34
【问题描述】:
我有一个引用 Location 模型的 Customer 模型。在数据库表中,customers 表有一个外键 location_id 到 locations 表。
这种关系是单向的。我的意思是,Location 是一个独立的实体,与 Customer 没有任何关系。
我拥有的是 客户.rb
:belongs_to :location
Location.rb 中没有任何内容。
什么是客户和位置的正确关联?我应该如何在新方法中构建对象?
我现在得到的错误是—— Location(#70161843915060) 预期,得到 ActionController::Parameters(#70161815174700)
更新 - 1
我的表单是为@customer 使用的
f.fields_for :location
参数如下—— 参数:{"utf8"=>"✓", "authenticity_token"=>"Kz0iGeAA/pxWvZy3vORKshSdQSBndwlWiHiih8lKYqHsggL/sTBPlaukpVanyckdProZyI3zik2N07udpySvMA==", "customer"=>{"name"=>"MNC", "location"=>{"name "=>"HY"}
【问题讨论】:
标签: ruby-on-rails activerecord database-design