【问题标题】:rails will_paginate rendering error in viewrails will_paginate 视图中的渲染错误
【发布时间】:2013-04-01 14:13:10
【问题描述】:

我无法使用 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

我找不到这里有什么问题:(

【问题讨论】:

  • 你能把错误贴出来
  • 我已经在第一行发布了错误。这是#<0x007fe098856378>

标签: ruby-on-rails will-paginate


【解决方案1】:

您将分页小部件 () 与可用元素列表混合在一起。你想要的是:

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

【讨论】:

  • 不工作。现在我得到了分页视图。但它什么也没做。我不能点击链接。这是截图。i.imgur.com/Lv5WjFj.png
【解决方案2】:

问题解决了!使用:page =&gt; params[:page] 而不是:page =&gt; 1 谢谢大家

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-11
    • 2013-05-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多