0

I have seen a couple of questions on this and tried them but it doesn't help. I am using will_paginate 3.0.7 gem. Where exactly am I going wrong?

Here is my code:

Categories_controller.rb:

def show
  @category = Category.includes(:products).find(params[:categoryid])
  @products = @category.products.paginate(page: params[:page], per_page: 10)
end

_product.html.erb

<%= will_paginate %>
  <ul class="categories">
    <% @products.each do |product| %>
    <li>
      <%= link_to product.productname,product %>
    </li>
  </ul>

Thank you

Suma Chaganti
  • 165
  • 1
  • 9

2 Answers2

3

You're missing @products as an argument to will_paginate. Also, missed to end your loop. Try this:

<%= will_paginate @products %>
<ul class="categories">
  <% @products.each do |product| %>
    <li>
      <%= link_to product.productname,product %>
    </li>
  <% end %>
</ul>

Hope this helps.

moeabdol
  • 4,779
  • 6
  • 44
  • 43
0

I had a very similar issue with the exact same type of naming and structure. Renaming the variable actually fixed it. So instead of:

  @products = @category.products.paginate(page: params[:page], per_page: 10)

You may want to try this:

  @category_products = @category.products.paginate(page: params[:page], per_page: 10)

Cf. https://stackoverflow.com/a/62977623/11293450.

NZisKool
  • 189
  • 3
  • 11