Has many association

Michael edited this page Sep 18, 2015 · 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
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.