xamenrax
xamenrax

Reputation: 1744

paginate nested resource with kaminari

Sup! I have

@comment = @photo.comments.create(...)

And I need to paginate this comments somehow, in the view:

- @photo.comments.each do |comment|
  ...

But I'm stucked, so help me please.

Do I need define @comments to add pagination?

Upvotes: 1

Views: 1339

Answers (1)

vikas
vikas

Reputation: 678

Ya I think we need to define @comments.

In controller -

@comments = @photo.comments.page(params[:page])

In view -

<% @comments.each do |comment| %>
<%= comment.attribute_name %>
<% end %>
<%= paginate @comments %>

I tried this and it worked.

Upvotes: 5

Related Questions