Reputation: 12476
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
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
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