Reputation: 471
The current page that I have been working on is a page where a user can create a comment under a specific micropost. All the microposts are shown on the same page and those microposts are paginated. Under each specific micropost, there are comments and those comments should be paginated and the issue I am currently having is that the pagination only happens when the HTML code is this:
HTML
<div id='comments'>
<%=render @comments %>
<%= will_paginate @comments, :class =>"pagination" %>
</div>
But the thing is when it is like that only the comments for the first micropost will show up on every single micropost rather than the specific micropost comments. So I figured why not put the code like this:
HTML
<div id='comments'>
<%=render micropost.comments %>
<%= will_paginate @comments, :class =>"pagination" %>
</div>
This basically set all the specific comments in the right micropost BUT it didn't paginate but the pagination links showed, so I figured putting this would work but it didn't, got an error:
HTML
<div id='comments'>
<%=render micropost.comments %>
<%= will_paginate micropost.comments, :class =>"pagination" %>
</div>
I am very confused and unsure what to do and yes the micropost is suppose to have no @
I would appreicate any suggestions that would help! Thank you!
My User#Show
User Controller
class UsersController < ApplicationController
def show
@user = User.find_by_id(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
Upvotes: 0
Views: 570
Reputation: 2736
This will work, but the fact that you need to do an assignment inside your view tells you this is probably not the way to do it:
<div id='comments'>
<% comments = micropost.comments.paginate(:per_page => 10, :page => params[:page]) %>
<%= render comments %>
<%= will_paginate comments, :class =>"pagination" %>
</div>
Do realize that the micropost & comments both use the same page parameter. So that if you want to view the second page of comments of any of the given microposts you will also switch to the second page of microposts. I would reconsider showing all this information on the same page.
Upvotes: 1