Considering you have a Contact Model, you can add a class method in it
like so
class self.find_contacts_for_a_group(group_id,page)
paginate(:all, :conditions => ['user_groups.group_id=?', group_id],
:joins => "as contacts inner join
user_groups as user_groups on user_groups.contact_id=contacts.id",
:page => page,
:per_page => 20)
end
and in your controller, lets say you create a method called
show_contacts like so:
def show_contacts
Contact.find_contact_for_a_group(params[:group_id], params[:page])
end
That should be it.
Nasir