I'm using handles_sortable_columns to sort my columns in Rails 3 and was wondering if there is a way to sort by a column in another table other than using a join.
I have a column that is a lookup of the name of a column in another table.
That is, I have cities.country_id as a column and in the View template I do:
@cities.each do |city|
city.country.name
to display the name.
I would like to be able to sort by this column, but the countries.name, not the cities.country_id.
Does anyone know if this possible with the gem or any other simple way? If so how?
The only thing I can think of is to do an IF statement in the controller and catch the sorting by country and then run a different query using a join for that, but that's ugly and error-prone, was hoping for something more elegant.
Thanks.