Go Back   CodingForums.com > :: Server side development > Ruby & Ruby On Rails

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
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
Reply

Bookmarks

Tags
habtm, has and belongs to many, list, order, relationship

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:46 AM.


Advertisement
Log in to turn off these ads.