【问题标题】:Ruby on Rails will_paginate - NoMethodErrorRuby on Rails will_paginate - NoMethodError
【发布时间】:2014-08-27 14:28:05
【问题描述】:

我正在尝试对我的项目列表进行分页,但不知何故它不起作用。我对 ruby​​ 很陌生。

我通过将 gem 'will_paginate', '~> 3.0.5' 添加到 gemfile 并在控制台中运行 bundle install 来安装 will_paginate。

之后我将控制器更改为看起来像

def index
  #@productions = Production.all
  @productions = Production.paginate(:per_page => 25, :page => params[:page])
end

并添加到我的index.html.erb 文件中:

<h1>Listing productions</h1>
<%= link_to 'New production', new_production_path %>
<table>
  <tr>
    <th>Date</th>
    <th>Time</th>
    <th>Area</th>
    <th>Items</th>
  </tr>

  <% @productions.each do |production| %>
    <tr>
      <td><%= production.date.strftime("%m/%d/%Y") %></td>
      <td><%= production.timefrom.strftime("%H:%M") %> to <%= production.timeto.strftime("%H:%M") %></td>
      <td><%= production.area %></td>
      <td><%= production.items %></td>
      <td><%= link_to 'Show', production_path(production) %></td>
      <td><%= link_to 'Edit', edit_production_path(production) %></td>
      <td><%= link_to 'Destroy', production_path(production),
                    method: :delete, data: { confirm: 'Are you sure?' } %></td>
    </tr>
  <% end %>
</table>
<%= will_paginate @productions %>

但是当我重新加载页面时它仍然会出现这个错误:

NoMethodError in ProductionsController#index
undefined method `paginate' for #<Class:0x5225898>

谁能告诉我为什么?或者给我一个提示?

【问题讨论】:

  • 你重启你的开发服务器了吗?
  • 天哪。我想就是这样......
  • 我敢肯定。
  • 太好了,现在基本上可以使用了,但是如果我添加def index #@productions = Production.all @productions = Production.paginate(:per_page =&gt; 25, :page =&gt; params[:page], :order =&gt; 'Date') end,它仍然会出现错误?
  • 它在ProductionsController中出现`NoMethodError#index undefined method apply_finder_options' for #&lt;Production::ActiveRecord_Relation:0x530f958&gt;

标签: ruby-on-rails ruby ruby-on-rails-3 will-paginate


【解决方案1】:

您应该重新启动您的开发服务器。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-20
    • 1970-01-01
    • 1970-01-01
    • 2017-06-02
    • 1970-01-01
    • 1970-01-01
    • 2011-03-13
    相关资源
    最近更新 更多