views:

39

answers:

1

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?

+1  A: 

Try passing the condition explicitly:

@clients = current_user.clients.paginate(
    :conditions => {:completed => false}, 
    :page => params[:page], :per_page => 10, 
    :order => 'started_on DESC')
Toby Hede
Cool, that worked. Thanks.
Senthil
Also, look into named scopes, this way you could do: `current_user.clients.completed.paginate(...)`.
jonnii
Good point. Once a condition is working for me, I generally pull it up into a scope if I am planning on using it more than once.
Toby Hede