Skip to content

Has many association

Nami-Doc edited this page May 19, 2014 · 7 revisions

Synopsys:

class Team < ActiveRecord::Base
  has_many :players, :dependent => :destroy, :inverse_of => :team

  # for a nested form: (natural choice for 1-n associations)
   
    accepts_nested_attributes_for :players, :allow_destroy => true
    
    # uncomment if you don't use strong parameters
    # attr_accessible :players_attributes, :allow_destroy => true

  # for a multiselect widget:
    # uncomment if you don't use strong parameters
    # attr_accessible :player_ids

  rails_admin do
    configure :players do
      # configuration here
    end
  end
end

# for info
class Player < ActiveRecord::Base
  belongs_to :team, :inverse_of => :players
end

More here

Clone this wiki locally