0

For some reason Kaminari is not limiting child objects on the parent show view.

Can see the pagination links but the collection does not get limited.

What am I doing wrong?

View -

     <% if @handbag.microposts.any? %>
        <h3>Posts (<%= @handbag.microposts.count %>)</h3>
<div class="row">
  <div class="col-md-8">
        <ol class="microposts">
          <% @handbag.microposts.each do |micropost| %>
             <li id="micropost-<%= micropost.id %>">
              <span class="user"><%= micropost.user.email %></span>
              <span class="content"><%= micropost.content %></span>
              <%= image_tag micropost.picture.url if micropost.picture? %>
              <span class="timestamp">
                Added <%= time_ago_in_words(micropost.created_at) %> ago.
              </span>
            </li>
          <% end %>
        </ol>
      <%= paginate @microposts %>

Controller -

  def show
    @handbag = Spree::Handbag.find(params[:id])
    @microposts = @handbag.microposts.page(params[:page] || 1).per(10)
  end

Thanks for any help.

AndrewJL
  • 128
  • 2
  • 12

1 Answers1

0

You're looping through @handbag.microposts, which is the entire collection, instead of @microposts, which is the paginated collection.

So just change @handbag.microposts.each to @microposts.each

baron816
  • 701
  • 4
  • 13
  • And just a few suggestions: you don't need the || 1 operation. That's done automatically. I also think you should look into using the facade pattern. It'll help organize your code better https://robots.thoughtbot.com/sandi-metz-rules-for-developers – baron816 Oct 22 '15 at 13:59
  • Thanks so much baron, was concentrating way too hard on the pagination elements. I'll have a look at facade pattern too, getting tired of bumbling around with other peoples Spree code. – AndrewJL Oct 22 '15 at 14:25