Ruby on rails 3.2 多态关联,有一个和多个通过错误多态关联
我正在研究一个多态关联问题,我不太确定该怎么做 以下是我当前的模型设置:Ruby on rails 3.2 多态关联,有一个和多个通过错误多态关联,ruby-on-rails-3.2,polymorphic-associations,Ruby On Rails 3.2,Polymorphic Associations,我正在研究一个多态关联问题,我不太确定该怎么做 以下是我当前的模型设置: 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, :maile
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
class-Rfqtrue
有一个:mailer,:through=>:partable
接受:mailer的\u嵌套\u属性\u
终止
类Mailer:partable#这应该/可能是属于??
终止
当我在浏览器中转到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" %>
ActiveRecord::HasmanyThroughAssociation多态性通过RFQ中的错误进行编辑
不能有一个has#mu many:through关联'Part#mailer',它通过多态关联'Part#partable'。
提取的源(第5行附近):
2:
3:
4:零件信息:
5:
6:builder%>
7:
8:“添加邮件部分”%>
我不确定问题出在哪里,因为我不想在任何地方建立一种关系 问题在于零件模型。您通过多态的
所属的拥有一个关联
我还没有答案给你。。。但这回答了你的问题。我认为这只是一个标签很差的常量,或者是像我们这样试图做他们不想/不想做的事情的人重复使用的常量
从表面上看,我认为这是因为DB没有partable
列,而是partable\u id
和partable\u type
问题在于零件模型。您通过多态的所属的拥有一个关联
我还没有答案给你。。。但这回答了你的问题。我认为这只是一个标签很差的常量,或者是像我们这样试图做他们不想/不想做的事情的人重复使用的常量
从表面上看,我认为这是因为DB没有partable
列,而是partable\u id
和partable\u type