Question

I have a comment model that posts under a micropost like facebook. The problem is that I don't think I am writing the right code under the user show in the user controller and that is what is making this error pop up. Any suggestions? All help is much appreciated!

Error

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: 

This is my current user show page:

User Controller

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

Thank you any suggestions are welcomed!

EDIT

<div id='comments'>
<%=render micropost.comments %>
<%= will_paginate @comments, :class =>"pagination" %>
</div>
Was it helpful?

Solution

try doing <%= will_paginate @comments, :class =>"pagination" %>

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top