Paginate ordering doesn't work when using find_all_by_completed(false)
-
22-09-2019 - |
Question
In my project model
def incomplete
@clients = current_user.clients.find_all_by_completed(false).paginate
(:page => params[:page], :per_page => 10, :order => 'started_on DESC')
end
For some reason it doesn't order started_on descending. However ordering works in another method
def all
@clients = current_user.clients.paginate(:page => params[:page], :per_page => 25, :order => 'started_on DESC')
end
So I'm assuming using find_all_by_completed is throwing off paginate. I'm using will-paginate btw. Any help?
Solution
Try passing the condition explicitly:
@clients = current_user.clients.paginate(
:conditions => {:completed => false},
:page => params[:page], :per_page => 10,
:order => 'started_on DESC')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow