Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Product < ActiveRecord::Base
- has_many :announcement_products
- has_many :announcements, :through => :announcement_products
- accepts_nested_attributes_for :announcements, :reject_if => lambda { |a| a[:content].blank? }, :allow_destroy => true
- end
- class Announcement < ActiveRecord::Base
- has_many :announcement_products
- has_many :products, :through => :announcement_products
- accepts_nested_attributes_for :products, :reject_if => lambda { |a| a[:content].blank? }, :allow_destroy => true
- end
- class AnnouncementProduct < ActiveRecord::Base
- belongs_to :announcement
- belongs_to :product
- end
- -------------
- CONSOLE
- a = Announcement.new()
- a.products << Product.first
- a.products << Product.last
- a.name = 'foo'
- a.description = 'bar'
- a.save!
Add Comment
Please, Sign In to add comment