user1502223
user1502223

Reputation: 645

will paginate coming out reversed

I'm using will paginate on my ruby on rails app..I've used this before on other apps and it was working fine however when i used it on this one for some reason it looks like the tabs for the pagination are reversed.

Here's the html

<div class="container">
 <br />
 <br />
 <h2 class="black">
Recent News
<div class="line_section"><div>
 </h2>
 <div class="row"> 
<div class="span12">

<ul class="recent-news"> 

<% @news_all.each do |news| %>

 <li style="font-size: 16px; line-height: 19px; letter-spacing: 1px; font-size: 14px;  color: #555; text-align: left;">
  <%= image_tag news.photo.url, class: 'pull-left', style: 'margin-right:40px; margin-top: 2px; width: 300px;' %> 
  <div style=" width: 600px; float: right;">
   <%= link_to news.title, news %> 
  <br />

   <%= link_to news.date, news, style: 'font-size: 10px; color: black; position: relative; top: 15px;' %> 

   <br /><br />
  <%= truncate news.content, length: 500 %> 
   <br />  
    <%= link_to 'Read More...', news, style: 'font-size: 12px !important;' %>
  </div>
      </li>
      <% end %> 

     <%= will_paginate @news_all %>
        </div><!-- end span12 -->


    </div><!-- end row -->
          </div><!-- end container -->

here's the controller

     def batnews
      @article = Article.first
      @news_all = News.all
      @news_all = News.paginate(page: params[:page]).limit(4)
      @comments = Comment.all
    end

here's the link to the site so you can see what's actually going on.

http://www.batman-fansite.com/batnews

if you scroll to the way bottom you will see the pagination.

Upvotes: 1

Views: 107

Answers (3)

Jay Vomex
Jay Vomex

Reputation: 11

Try something like this:

def index

@posts = Post.paginate :page => params[:page], **:order => "created_at ASC"**
end

Upvotes: 0

Winfield
Winfield

Reputation: 19145

There are two problems here:

  • Display order is incorrect due to CSS float:right, causing elements to go right in order rendered, which results in backwards order left-to-right.
  • Using limit(4) on paginated set vs. per_page: 4 option in pagination.

Check your CSS, you'll find:

.recent-news li {
  float: right;
}

...and your controller code should be:

 @news_all = News.paginate(page: params[:page], per_page: 4)

Upvotes: 1

dimuch
dimuch

Reputation: 12818

Fix you css:

.recent-news li {
   float: right;
}

add something like

.recent-news .pagination li {
   float: left;
}

Upvotes: 1

Related Questions