2013-05-25 32 views
0

我has_and_belongs_to_many不工作在我的節目來看,在形式,我能夠選擇多個選項,但他們不會顯示在show.html.erbhas_and_belongs_to_many作品在形式,但沒有表現出

我區間控制器

class Section < ActiveRecord::Base 
    attr_accessible :about, :name 

has_and_belongs_to_many :products 
end 

我的產品控制器

class Products < ActiveRecord::Base 
     attr_accessible :price, :name, :section_id 

    has_and_belongs_to_many :sections 
    end 

在我的節目鑑於

<%=h @product.section.name %> 

創建和呈現出產品

回答

0

你讀這個權利的時候如何顯示所有選擇的部分? http://guides.rubyonrails.org/association_basics.html

我認爲在產品類中不應該有section_id,但如果您有一個「特殊」部分,這可能是有道理的。

如果你做得對,你的朋友是@product.sections(注意複數)。

乾杯,

相關問題