rails 分页
基本步骤
1.安装will_paginate
编辑GemFile,添加一行:gem ‘will_paginate’
然后执行:
$ bundle install
2. 修改config/environment.rb文件
在config/environment.rb 文件的最后添加
require'will_paginate'
3. 选择你要加分页的控制器(controller文件)
没加分页前的代码
def history @score = Score.all render 'search' end
添加后代码
def history @scores = Score.paginate :page => params[:page], :per_page => 10 render 'search' end
4. 修改viem
代码
<%= form_tag('/history') do %> <%= submit_tag('历史查询') %> <% end %> </div> <% if @scores != nil %> <table> <tr> <th>帐号</th> <th>姓名</th> <th>沟通能力</th> <th>职业素养</th> <th>学习能力</th> <th>演讲能力</th> <th>综合能力</th> <th>周</th> </tr> <% @scores.each do |score| %> <tr> <td><%=User.find_by_name(score.name).user_id %></td> <td><%= score.name %></td> <td><%= score.ability_to_communicate %></td> <td><%= score.professional_quality %></td> <td><%= score.ability_to_learn %></td> <td><%= score.speech_ability %></td> <td><%= score.comprehensive_ability %></td> <td>第<%= score.number %>周评分</td> <td><%= link_to '修改', edit_path(score) %></td> </tr> <% end %> </table> <%= will_paginate @scores, :previous_label => '上一页', :next_label => '下一页' %> <% end %>
添加了
<%= will_paginate @scores, :previous_label => '上一页', :next_label => '下一页' %>
重启服务器
相关推荐
wl00 2020-10-28
EricNet 2020-07-05
EricNet 2020-05-27
何志文 2020-05-11
JOO 2020-04-26
happyfreeangel 2020-04-09
Poisedflw 2020-03-23
yangliuhbhd 2020-03-06
Ben的程序员生涯 2013-06-01
chenshuixian 2013-06-01
wes0 2014-05-31
mrice00 2019-12-20
EricNet 2019-12-11
89304896 2019-12-08
lihaoningxia 2013-07-09
userguanguan 2015-03-16