sent-hil
sent-hil

Reputation: 19285

Paginate ordering doesn't work when using find_all_by_completed(false)

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?

Upvotes: 4

Views: 1407

Answers (1)

Toby Hede
Toby Hede

Reputation: 37133

Try passing the condition explicitly:

@clients = current_user.clients.paginate(
    :conditions => {:completed => false}, 
    :page => params[:page], :per_page => 10, 
    :order => 'started_on DESC')

Upvotes: 4

Related Questions