0

My has_and_belongs_to_many doesnt work in my show view, In the form i am able to select multiple options but they wont display in the show.html.erb

My Section Controller

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

has_and_belongs_to_many :products
end

My Products Controller

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

    has_and_belongs_to_many :sections
    end

In my show view

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

How do I display all chosen section when creating and showing a product

PMP
  • 231
  • 6
  • 25

1 Answers1

0

You read this right? http://guides.rubyonrails.org/association_basics.html

I think there should not be a section_id in the product class, but if you have a "special" section this might make sense.

If you did it right your friend is @product.sections (note the plural).

Cheers,

Idavod
  • 167
  • 5