我有一个评论模型,在facebook这样的微博下发布。问题是我不认为我在用户控制器的用户节目下编写正确的代码,这就是弹出此错误的原因。有什么建议?非常感谢所有帮助!
错误
NoMethodError in Users#show
Showing /Users/Brian/rails_projects/stateschool/app/views/microposts/_micropost.html.erb where line #70 raised:
undefined method `total_pages' for #<ActiveRecord::Relation:0x007fc8c2f83468>
Extracted source (around line #70):
67: <%= render :partial => "comments/form", :locals => { :micropost => micropost } %>
68: </div>
69: <div id='comments'>
70: <%= will_paginate micropost.comments, :class =>"pagination" %>
71: </div>
72: </div>
73:
这是我当前的用户展示页面:
用户控制器
class UsersController < ApplicationController
def show
@user = User.find(params[:id])
@school = School.find(params[:id])
@micropost = Micropost.new
@comment = Comment.new
@comment = @micropost.comments.build(params[:comment])
@comments = @micropost.comments.paginate(:page => params[:page], :per_page => 10)
@microposts = @user.microposts.paginate(:per_page => 10, :page => params[:page])
end
end
谢谢欢迎任何建议!
修改
<div id='comments'>
<%=render micropost.comments %>
<%= will_paginate @comments, :class =>"pagination" %>
</div>
答案 0 :(得分:1)
尝试做 &lt;%= will_paginate @comments,:class =&gt;“分页”%&gt;