I am not sure how to figure this one out, because I dont know how I would update my intermediary table, without having to do delete_all. Or where to do inserts and deletes, etc.
I have three classes:
class User < ActiveRecord::Base
has_many :players
has_many :teams, :through => :players
end
class Team < ActiveRecord::Base
has_many :players
end
class Player < ActiveRecord::Base
belongs_to :team
belongs_to :user
(contains other columns like, is_captain, has_paid, etc.)
end
I am displaying a page with checkboxes and you can select which ‘users’ you would like to be on your team (from your AddressBook). So imagine 25 names listed, and some of them are already checked and others are not. How could I save the data of checkboxes, cause they may have 3 different states: 1) insert brand new player (insert row into player) 2) remove player from team (delete existing player) or 3)do nothing (a player you dont want on your team)
The issue i am running into is that when you ‘uncheck’ a box, then the front-end does not send that to back-end? Any ideas how this can be done nicely?
Not sure if this is the best way to do this but it works, I am open to recommendations in improving this code