ActiveRecord_Relation的未定义方法`total_pages'

时间:2015-10-01 01:19:47

标签: ruby-on-rails ruby

我已经看到了几个关于此的问题并尝试了它们,但它没有帮助。我正在使用will_paginate 3.0.7 gem。我到底哪里错了?

这是我的代码:

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>

谢谢

2 个答案:

答案 0 :(得分:2)

您遗漏Range("R8:R" & FinalRow).Formula = "=IFERROR(HLOOKUP(IF(RIGHT(INDIRECT(Address(Row()-13,Column()+2)))=""B4"",INDEX('[" & MyNM & " " & MyCC & " " & MyUnit & " EVMS.xlsm]" & myUA _ & "'!D:E,MATCH(INDIRECT(Address(Row(),Column()+4)),'[" & MyNM & " " & MyCC & " " & MyUnit & " EVMS.xlsm]" & myUA & "'!E:E,0),1)," _ & "INDEX(INDIRECT(""'[" & MyNM & " " & MyCC & " " & MyUnit & " EVMS.xlsm]""&RC5&""'!D:E"",TRUE)," _ & "MATCH(INDIRECT(Address(Row(),Column()+4)),INDIRECT(""'[" & MyNM & " " & MyCC & " " & MyUnit & " EVMS.xlsm]""&RC5&""'!E:E"",TRUE),0),1))" _ & ",'[" & MyNM & " " & MyCC & " " & MyUnit & " EVMS.xlsm]SOP'!INDIRECT(ADDRESS(ROW()+1,COLUMN()+3 &":"& ADDRESS(ROW()+4, COLUMN()+41)),4,FALSE),""NP"")" 作为@products的参数。此外,错过了你的循环。试试这个:

will_paginate

希望这有帮助。

答案 1 :(得分:0)

在命名和结构完全相同的情况下,我遇到了一个非常相似的问题。重命名变量实际上已将其修复。所以代替:

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

您可能想尝试一下:

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

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