Rails3 分页插件will_paginate

环境:ruby1.9.3, rails 3.2.6

 

 

1. 在Gemfile文件中增加,后在命令行中执行bundle install,下载will_paginate 包

 

gem 'will_paginate', '~> 3.0'

bundle install

 

安装成功信息:

Installing will_paginate (3.0.3)

Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem

is installed.

 

2. 在控制器中,修改index函数

 

@areas = Area.all

修改为:

@areas = Area.paginate(:page => params[:page], :per_page => 5)
 

:per_page 每页显示记录的条数

 

3. 修改视图文件index.html.erb

 

在文件的最后加上

 

<%= will_paginate @areas %>

 

4. 加上CSS显示效果

 

在asstes/css下增加 pagination.css文件

内容在http://mislav.uniqpath.com/will_paginate 中下载,或者其他样式

 

修改

<%= will_paginate @areas %>

<div class="digg_pagination">
  <div clas="page_info">
    <%= page_entries_info @areas %>
  </div>
  <%= will_paginate @areas, :container => false %>
</div>

效果如下:

5.相关材料

[wiki]: https://github.com/mislav/will_paginate/wiki

[install]: https://github.com/mislav/will_paginate/wiki/Installation "will_paginate installation"

[group]: http://groups.google.com/group/will_paginate "will_paginate discussion and support group"

[issues]: https://github.com/mislav/will_paginate/issues

[css]: http://mislav.uniqpath.com/will_paginate/

 

你可能感兴趣的:(will_paginate)