I set up a test application using the kaminari gem for pagination. This is what my my music video controller's show action looks like:
def show
@music_video = MusicVideo.find(params[:id])
@comments = @music_video.comments.page(params[:page]).per(3)
end
And here is what my show view looks like:
<p id="notice"><%= notice %></p>
<p>
<strong>Name:</strong> <%= @music_video.name %>
</p>
<% @comments.each do |comment| %>
<p>
Comment: <%= comment.text %>
</p>
<% end %>
<%= paginate @comments %>
<%= link_to 'Edit', edit_music_video_path(@music_video) %> |
<%= link_to 'Back', music_videos_path %>
It is working and the pagination is showing up for me.
I think one thing i see directly is that you should use <% @comments.each do |comment| %>
instead of <% @music_video.comments.each do |comment| %>
because the way you have it now it will display all comments for the video regardless of what page you are on. If you had 6 comments and wanted 3 per page you would see the pagination with the two pages because you're running your pagination based off of @comments
and you would end up seeing all 6 comments on both pages because you're doing your .each
with @music_videos.comments.each
.
So, at least using @comments
in both places would be a start. And make sure you're using <%= paginate @comments %>
for the pagination. If you use this in your controller and view what do you get? Do you see any comments?
Also, Ryan Bates has a great screencast on Kaminari as well: http://railscasts.com/episodes/254-pagination-with-kaminari (that site is a great resource for rails questions)