I have the following tables – groups, contacts, contacts_groups (habtm join table)
groups & contacts are owned by a user and both have user_id columns
Question:
When I am in the groups controller and I want to access all the contacts that belong to that group how do I do this?
url looks like
http://localhost:3000/users/2/groups/5
my view looks like this
<p>
<b>Name:</b>
<%= @group.name %>
</p>
<p>Associated Contacts</p>
<% @contacts.each do |contact| %>
<tr>
<td><%= contact.firstname %></td>
<% end %>
in my Groups controller i have
def show
@contacts = Contact.accessible_by(current_ability)
end
This returns ALL contacts the current user has access to. How can I return the contacts that belong to the group i am currently viewing?
Thanks!!
I would try this:
So the view would be: