cola
cola

Reputation: 12476

Ruby on Rails: will_paginate is not working correctly

If I click the next or previous link it doesn't go to the next or previous page.

All posts are on same page, but there are links next, previous at bottom.

In PostsController:

@posts = Post.paginate(:per_page => 15, :page => params[:page], :order => 'created_at DESC')

in posts/index:

<%= will_paginate @posts%>

Where is the problem with will_paginate?

Upvotes: 0

Views: 4862

Answers (3)

ispirett
ispirett

Reputation: 666

Updating to will_paginate , '3.1.7' solved my issues

Upvotes: 1

eveevans
eveevans

Reputation: 4460

You have to order before paginate, so, change it to

@posts = Post.order('created_at DESC').paginate(:per_page => 15, :page => params[:page])

Upvotes: 2

user568278
user568278

Reputation:

Not sure if this is causing your error, but ordering should be done outside of will_paginate.

@posts = Post.paginate(:per_page => 15, :page => params[:page]).order('created_at DESC')

This is how it should be done in Rails 3.

I've also had trouble setting the per_page parameter within the controller. You could try setting it in the model instead.

class Post
  self.per_page = 10
end

Upvotes: 1

Related Questions