私はポリモーフィック アソシエーションの問題に取り組んでいますが、どこに行けばよいのかよくわかりません。
これが私の現在のモデル設定です:
class Rfq < ActiveRecord::Base
attr_accessible :name, :parts_attributes
has_many :parts
accepts_nested_attributes_for :parts
end
class Part < ActiveRecord::Base
attr_accessible :name, :mailer_parts
belongs_to :rfq
belongs_to :partable, :polymorphic => true
has_one :mailer, :through => :partable
accepts_nested_attributes_for :mailer
end
class Mailer < ActiveRecord::Base
attr_accessible :address
has_one :part, :as => :partable # Should/could this be belongs_to?
end
ブラウザーで Rfq の編集ページに移動すると、次のエラーが表示されます。
ActiveRecord::HasManyThroughAssociationPolymorphicThroughError in Rfqs#edit
Cannot have a has_many :through association 'Part#mailer' which goes through the polymorphic association 'Part#partable'.
Extracted source (around line #5):
2: <%= f.label :name, "Name" %>
3: <%= f.text_field :name %><br>
4: <p>Part Information: </p>
5: <%= f.fields_for :mailer do |builder| %>
6: <%= render 'mailer_fields', :f => builder %>
7: <% end %>
8: <%= link_to 'Add Mailer Part', '#', :class => "add_mailer_part" %>
どこでも has_many 関係を実行しようとしていないため、問題がどこにあるのかわかりません。