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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
334ae822566107a2ea2b7a7cb88bd1d6?d=identicon&s=25 Brutyn Nick (Guest)
on 2005-12-14 17:18
(Received via mailing list)
hey,
i my database i have users and groups, each user can get in different
groups

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
end
class User < ActiveRecord::Base
    has_and_belongs_to_many :groups
end

i want this
http://wiki.script.aculo.us/scriptaculous/show/Sor...
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.