简体   繁体   English

Ruby on Rails的will_paginate-NoMethodError

[英]Ruby on Rails will_paginate - NoMethodError

I am trying to paginate my List of Items but somehow its not working. 我正在尝试对我的项目列表进行分页,但不知何故它不起作用。 I am pretty new to ruby. 我对红宝石很陌生。

I installed will_paginate by adding gem 'will_paginate', '~> 3.0.5' to the gemfile and running bundle install in the console. 我通过将gem 'will_paginate', '~> 3.0.5'到gemfile并在控制台中运行bundle install来安装will_paginate。

After that I changed my controller to look like 之后,我将控制器更改为

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

and to my index.html.erb file I added: 并添加到我的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 %>

But it still comes up with this error when I reload the page: 但是当我重新加载页面时,仍然出现此错误:

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

Can someone tell me why? 有人可以告诉我为什么吗? Or give me a hint? 还是给我一个提示?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM