Rails 2.3.5 / Ruby 1.8.6
I have a ‘teams’ table that contains a ‘center’ id (center_id) field (teams belongs to center and center has many teams). In the views, I’m using the name of the center:
Controller (sorting by team 'name':
@teams= Team.find(:all, :order => "name ASC")
View:
<%=h team.center.center_name %>
How can I sort the query by the by center name? Like:
@teams= Team.find(:all, :order => "center.center_name ASC name ASC")
I’m not even sure if this is possible… Should I be trying to solve this be adding logic to the “@teams.each do |team|” loop? Or maybe by collecting the query results into a normal array and then sorting the array?
Thank you!
Looks like you’re pretty close. Do you have a ‘centers’ table? If so try: