Getting will_paginate to reorder a page

I'm trying to get will_paginate to order my posts so that a new post appears at the top of the first page, but I can't figure out how to do this.

This is the order when I sort ...order(:published_at)

Page 1

2014-08-05
2014-08-04
2014-08-03
2014-08-02
2014-08-01 <- Oldest post

Page 2

2014-08-10 <- Newest post
2014-08-09
2014-08-08
2014-08-07
2014-08-06

And this is what he does when I ...order("published_at DESC")it

Page 1

2014-08-06
2014-08-07
2014-08-08
2014-08-09
2014-08-10 <- Newest post

Page 2

2014-08-01 <- Oldest post
2014-08-02
2014-08-03
2014-08-04
2014-08-05

But this is the order that I really want:

Page 1

2014-08-10 <- Newest post
2014-08-09
2014-08-08
2014-08-07
2014-08-06

Page 2

2014-08-05
2014-08-04
2014-08-03
2014-08-02
2014-08-01 <- Oldest post
0
source share
1 answer

Unfortunately, in my case, I am my worst enemy.

That was my code in index.html.erb

<% @blog_posts.reverse.each do |blog_post| %>
  #            ^^^^^^^
  <%= render "blog_post", blog_post: blog_post %>
<% end %>

and this should be the code in my index.html.erb

<% @blog_posts.each do |blog_post| %>
  <%= render "blog_post", blog_post: blog_post %>
<% end %>

and in my controller

def index
  @blog_posts = BlogPost.
    published.
    page(params[:page]).
    order("published_at DESC")
end

Produces this order

Page 1

2014-08-10 <- Newest post
2014-08-09
2014-08-08
2014-08-07
2014-08-06

Page 2

2014-08-05
2014-08-04
2014-08-03
2014-08-02
2014-08-01 <- Oldest post
0
source

All Articles