我已經成功地創建了依賴多態關聯使用accepts_nested_attributes_for
,但現在我想分配一個已經存在的多態。我發現了錯誤:Rails多態分配
undefined method `id' for {"id"=>"4"}:ActiveSupport::HashWithIndifferentAccess
型號:
class Person < ActiveRecord::Base
has_one :address, :as => :addressable
end
class Company < ActiveRecord::Base
has_one :address, :as => :addressable
end
class Address < ActiveRecord::Base
belongs_to :addressable, :polymorphic => true
end
查看:
<%= form_for @company do |f| %>
<p>
<%= f.label :company_name %><br />
<%= f.text_field :company_name %>
</p>
<%= f.fields_for :address do |f| %>
<div class="field">
<%= f.collection_select :id, Address.all, :id, :description, {:prompt => "-Select Address"} %>
</div>
<% end %>
產生的PARAMS哈希:
"company"=>{"company_name"=>"myCompanyName", "address"=>{"id"=>"4"}}
它看起來合理的,我。我究竟做錯了什麼?
嘗試了你的建議。同樣的錯誤。在這種情況下,我的params散列應該是什麼樣子? – SooDesuNe 2011-02-13 22:27:14