Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
Thread: Ordering a HABTM relationship?
10-31-2010, 10:10 AM #1
- Join Date
- May 2009
- Glastonbury, UK
- Thanked 0 Times in 0 Posts
Ordering a HABTM relationship?
Hey there I have an app where:
- A user has and belongs to many videos
- A video has and belongs to many users. And belongs to a group.
- A group has many videos
On the 'Show' action of the user, I have it print out all the videos that user is in along with the group if that video. Here is a snippet of the ERB file.
<% if @user.videos !=  -%> <tr><th>I'm in these videos:</th></tr> <% for video in @user.videos -%> <tr><td><%= link_to video.name, video %> - <%= link_to video.group.name, video.group %></td></tr> <% end -%> <% else -%> <tr><th>This user is currently in no videos.</tr></th> <% end -%> </table>
Thanks in advance!