Re: Listing elements from a table

Robert Walker
2009-04-22T19:41:06Z

Stephen Fagan wrote:
> How would I define the members and groups in my controller to do this
> and also how could I list them in my views?

groups_controller.rb
-------------
def show
  @group = Group.find(params[:id]);
  ...
  ...
end

With groups you can get memberships:
memberships = @group.memberships

From memberships you get users:
memberships.each do |membership|
  membership.user
end

There are ways to get your ordering by taking advantage of named_scopes:
http://api.rubyonrails.org/classes/ActiveRecord/NamedScope/ClassMethods.html#M002120

Those are some of the things I can think of that should help you build
your group show pages. Hope this gives you some ideas on how to proceed.