Skip to content

Has and belongs to many association

bbenezech edited this page Nov 29, 2011 · 8 revisions

Synopsys:

class Team < ActiveRecord::Base
  has_and_belongs_to_many :fans, :inverse_of => :teams

  # 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
end

# for info
class Fan < ActiveRecord::Base
  has_and_belongs_to_many :teams, :inverse_of => :fans
end


RailsAdmin.config |config| do
  config.model Team do
    configure :fans do
      # configuration here
    end
  end
end

More here

Clone this wiki locally