ruby-on-railswill-paginate

rails will_paginate rendering error in view


I can't render my items on view using will_paginate. I get this error

undefined method `total_pages' for #<Enumerator:0x007fe098856378>

Here is my pagination on controller

@com = @text.comments.sorted.paginate(:page => 1, :per_page => 30)

and my view file code.

 <% will_paginate @com.each do |text| %>
<div class="comments"> <p class="time"><%= Time.now %></p> 
<p><%=  text.text %></p></div>

And the controller file is

def show
    @text = Microblog.find(params[:id])
    @com = @text.comments.sorted.paginate(:page => 1, :per_page => 2)
    @rating = (@text.up - @text.down)
  end

And the model file

class Comment < ActiveRecord::Base
    attr_accessible :text, :microblog_id
    belongs_to :microblog
    scope :sorted, order("comments.created_at DESC")
end

I can't find what is the problem here :(


Solution

  • You are mixing the pagination widget (< 1 2 3 >) with the listing of your available elements. What you want is:

    <% will_paginate @com %>
    <% @com.each do |text| %>
       <div class="comments"> <p class="time"><%= Time.now %></p> 
       <p><%=  text.text %></p></div>