を使用して依存ポリモーフィック アソシエーションの作成に成功しましたがaccepts_nested_attributes_for
、既存のポリモーフィックを割り当てたいと考えています。エラーが発生します:
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"}}
これは私には合理的に見えます。私は何を間違っていますか?