I have two Models here associated as such:
class Order < ActiveRecord::Base
belongs_to :customer
...
end
class Customer < ActiveRecord::Base
has_many :orders
end
A customer can have many orders and an order can belong to one customer. The thing is that I’m displaying a listed table where I show the following field values
ORDER ID| CUSTOMER NAME |...
Customer name refers to customer[:name] – I found out that you can sort by using the find method and passing in a join like so:
Order.find(:all, :joins => :customer, :order => 'customer.name asc')
however I need to paginate the results here and it seems I can’t do something like this – I’m using the Kaminari gem here for pagination:
Order.find(:all, :joins => :customer, :order => 'customer.name asc').page(5)
# doesn't work throws an error nomethoderror on page
Any ideas?
You should use the “new” Rails 3 query interface: