Okay, I'm sure there's a simple solution to my problem. Here is my controller.rb
code:
@photos = Photo.paginate :page=>params[:page], :order => "date DESC", :per_page => 2
For some reason, my sort order is not being respected. Pagination is functioning correctly (such as the number per page) but the order is not working at all. I've tried using different values like ASC
and DESC
as well as different fields to no avail. Here is my entire controller function after moving "order" first :
def index
@photos = Photo.all
@photos = Photo.order("date DESC").paginate(:per_page => 12, :page => params[:page])
respond_to do |format|
format.html # index.html.erb
format.json { render :json => @gallery }
end
end
I previously had this working perfectly in Rails 1, I just cannot figure this out with the will_paginate gem. As I mentioned, the :per_page
parameter is working so I know the pagination is working, I'm just getting no sorting and no errors. I would appreciate any help!