相关模型中的HashWithIn DifferentAccess
我有一个 Rails 应用程序,可以在其中链接两个数据库中的字段。数据库的东西似乎一切都很好。
但是,我有一种形式,可以将远程数据库中的描述映射到本地数据库中的产品。
当我提交表单时,用于创建产品和选择描述的表单工作正常
#_form.rb semantic_form_for @products do |f| f.input :name semantic_fields_for :description_maps do |description| description.input :desciption_map_id, :input_html=>{:name=>"product[description_map][description_id]}, :collection => @descriptions end end #product.rb class Product < ActiveRecord::Base attr_accessible :name, :description_map_attributes, :description_map has_one :description_map accepts_nested_attributes_for :description_map
,但出现错误,
DescriptionMap(#...) expected, got ActiveSupport::HashWithIndifferentAccess(#othernumber)
我似乎无法弄清楚为什么会发生这种情况。
发布的参数看起来不错
"product"=>{"name"=>"test name", "description_map"=>{"description_id"=>"1"}}
I've got a rails app where I'm linking fields across two databases. The database stuff all seems to be fine.
However, I have one form where I am mapping a description from the remote database to a product in the local database.
The form the used to create the product and select the description works fine
#_form.rb semantic_form_for @products do |f| f.input :name semantic_fields_for :description_maps do |description| description.input :desciption_map_id, :input_html=>{:name=>"product[description_map][description_id]}, :collection => @descriptions end end #product.rb class Product < ActiveRecord::Base attr_accessible :name, :description_map_attributes, :description_map has_one :description_map accepts_nested_attributes_for :description_map
when I submit the form, I get an error
DescriptionMap(#...) expected, got ActiveSupport::HashWithIndifferentAccess(#othernumber)
I can't seem to figure out why this is happening.
the parameters being posted look fine
"product"=>{"name"=>"test name", "description_map"=>{"description_id"=>"1"}}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
事实证明,这是一个关于描述图命名方式的问题。
在问题中,我已经指定,
但“description_map”需要是“description_map_attributes”,就像这样
希望这个答案可以帮助其他有同样问题的人。
turns out this was an issue with how formtastic was naming the description map.
In the question, i had specified
but the 'description_map' needed to be 'description_map_attributes' like this
Hopefully this answer helps somebody else having the same issue.
您应该使用: :description_map (不带“S”)因为是 has_on 关系
结束
You should use: :description_map (without "S") cause is a has_on relation
end