1

我无法使用 will_paginate 呈现我的项目。我收到这个错误

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

这是我在控制器上的分页

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

和我的视图文件代码。

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

控制器文件是

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

和模型文件

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

我在这里找不到问题所在:(

4

2 回答 2

3

您正在将分页小部件 (< 1 2 3 >) 与可用元素列表混合。你想要的是:

<% will_paginate @com %>
<% @com.each do |text| %>
   <div class="comments"> <p class="time"><%= Time.now %></p> 
   <p><%=  text.text %></p></div>
于 2013-04-01T15:41:15.943 回答
0

问题解决了!用来:page => params[:page]代替:page => 1 谢谢大家

于 2013-04-01T16:38:53.743 回答