View Single Post
Old 10-31-2010, 10:10 AM   PM User | #1
noisyscanner
New Coder

 
Join Date: May 2009
Location: Glastonbury, UK
Posts: 53
Thanks: 1
Thanked 0 Times in 0 Posts
noisyscanner is an unknown quantity at this point
Post 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.
Code:
<% 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>
Is there a way I can order the list by the group name?

Thanks in advance!
noisyscanner is offline   Reply With Quote