Skip to content

Has and belongs to many association

bbenezech edited this page Dec 26, 2012 · 5 revisions

Synopsys:

class Team < ActiveRecord::Base
  has_and_belongs_to_many :fans

  # for a multiselect widget: (natural choice for n-n associations)

    attr_accessible :fan_ids

  # for a nested form: 
   
    accepts_nested_attributes_for :fans, :allow_destroy => true
    attr_accessible :fans_attributes

  rails_admin do
    configure :fans do
      inverse_of :teams
      # configuration here
    end
  end
end

# for info
class Fan < ActiveRecord::Base
  has_and_belongs_to_many :teams
end

More here

Clone this wiki locally