244 shaares
118 liens privés
118 liens privés
2 résultats
taggé
many_many
# in model team
has_and_belongs_to_many :users
accepts_nested_attributes_for :users, allow_destroy: true, reject_if: :all_blank
accepts_nested_attributes_for :user, allow_destroy: true, reject_if: :all_blank
# Controller
params.require(:team).permit(:name, :users_attributes => [ :user_attributes => [:email] ] )
# In a helper, to manage non persistent manipulations on team.users
self.association(:users).add_to_target(user)
Team has and belongs to many users
Users has and belongs to many teams.
Users.all.where('id not in (?)', @team.users.map(&:id)
Returns the list of all users not related to the @team