Forum: Ruby on Rails how to get these records in has_and_belongs_to_many relation

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Brutyn N. (Guest)
on 2005-12-14 18:18
(Received via mailing list)
i my database i have users and groups, each user can get in different

my db structure:
table groups: id, name, basegroup, firm_id
table users: id, firstname, lastname, email
table groups_users: group_id, users_id

my relation is a many to many:
class Group < ActiveRecord::Base
    has_and_belongs_to_many :users
class User < ActiveRecord::Base
    has_and_belongs_to_many :groups

i want this
with ajax, first column the user who arent in the group, the second
column those
who are in the group. (is cooler than 2 oldschool selectlists ;) )

these are my users:
in group: Luc
not in group: Nick, Glenn, Andy

for the second colum i got this in my controller:
@group_users = Group.find(:first, :conditions =>['firm_id = ? and id =
@firm_id, @selected_group]).users

and in rhtml:
<% for user in @group_users %>
    <%= user.first_name %> <br/>
<% end %>

the output it get: Luc
(this is correct for the user who are in the group)

Bur now: who do i get the users Nick, Glenn and Andy???

Thanks in advance
This topic is locked and can not be replied to.