Sorting attribute in list from foreign table

Hello, I currently have two tables.

table_a (

table b (

So table A holds an id from table B. During the listing of tuples in
table A, it lists table A’s attributes. In place of the table B id, I
check the id, and instead display the name corresponding to that id. Now
I want to be able to sort the listing of tuples in table A by the names
of table B. Here is some code to hopefully help you understand more
clearly what I’m trying to do.

sort = case @params[:sort]
       when "last inserted"  then "id DESC"
       when "name"  then "" # <---- does not work

@table_a_pages, @table_as = paginate :table_a, :order => sort, 

:per_page => 10

At the noted line, I am unable to use to sort the list. Any
suggestions on how to solve this? Thanks!


you’ll need to include a reference to table b,

paginate builds a find statement, and you weren’t telling it to
include table_b

@table_a_pages, @table_as = paginate :table_a, :order =>  

:per_page => 10, :include => [:table_b]


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs