我正在尝试对我的项目列表进行分页,但是以某种方式无法正常工作。我对红宝石很陌生。
我通过添加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>
有人可以告诉我为什么吗?还是给我一个提示?
您应该重新启动开发服务器。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句