0
我已經看到了一些關於此問題的問題並嘗試了它們,但它沒有幫助。我正在使用will_paginate 3.0.7 gem。我究竟在哪裏出錯?ActiveRecord_Relation未定義的方法`total_pages'
這裏是我的代碼:
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>
謝謝
那麼你究竟想要做什麼?它是has_many belongs_to類別產品之間的關係嗎?你能展示模型代碼嗎? – moeabdol
是的,它的確如此。在類產品中,我有「belongs_to:category」,而在類別類別中,我有「has_many:products」 – Sumac
你可以在@category後面斷點並打印出它的內容 – moeabdol