Hi All,
I’m building an application that lists events (music gigs) along with
the corresponding venues and towns where they are happening. I followed
the tutorial at How to paginate, sort and search a table with Ajax and Rails · dev.nozav.org and can get
the list to sort by all columns except for by town, which is a parent of
venues, which in turn is a parent of gigs.
The relevant tables are set up as follows:
gigs (
id
artist_id
venue_id
date
)
venues (
id
name
town_id
)
towns (
id
name
)
The gigs_controller.rb is then set up as follows
def list
gigs_per_page = 20
sort = case @params['sort']
when "artist" then "artists.artist_name"
when "venue" then "venues.venue_name"
broken when “town” then “venues.towns.town_name”
when "date" then "date_time"
when "artist_reverse" then "artists.artist_name DESC"
when "venue_reverse" then "venues.venue_name DESC"
broken when “town_reverse” then “venues.towns.town_name DESC”
when "date_reverse" then "date_time DESC"
end
@gigs_pages, @gigs = paginate :gigs,
:order => sort,
:conditions => "date_time >= now()",
:per_page => gigs_per_page,
:include => [:artist, :venue]
end
So, what I want to do is sort the list according to the name of the town
in the same way as the other columns - any suggestions?
Cheers,
- Sandy