kaminari是一个基于范围和驱动的清洁的、强大的、可定制的而且复杂的现代Web应用程序框架和对象关系模型。它只请求当前页所需的数据,不会将表中全部数据加载完而后分页(很遗憾wice_grid就是这样的,据我所知),极大地提升了数据量大的应用的性能。javascript
易用:html
只需安装gem文件,而后你的model就能够分页了,不须要任何配置,也没必要在你的models或helpers中定义任务东西。
基于I18N的可定制引擎:
因为全部的分页帮助都是基于连接和非连接的容器,Kaminari在本身的引擎内部模板参考了他们,所以,你能很容易的修改
他们的行为、风格、或者重载模板的任何事情。
java
1.在gemfile文件中引入git
#分页插件 gem 'kaminari' gem 'bootstrap-kaminari-views'
3.生成配置文件(这不是必须的,彻底能够使用默认的,也可本身在程序中经过参数进行控制) github
rails g kaminari:config
Kaminari.configure do |config| # config.default_per_page = 25 # config.max_per_page = nil # config.window = 4 # config.outer_window = 0 # config.left = 0 # config.right = 0 # config.page_method_name = :page # config.param_name = :page end
class Book < ActiveRecord::Base #附件 has_many :attachments, as: :owner, dependent: :delete_all, autosave: true has_many :assets, through: :attachments accepts_nested_attributes_for :assets, allow_destroy: true accepts_nested_attributes_for :attachments, allow_destroy: true paginates_per 2 #每页显示两条数据 end
5.修改books_controller.rb文件json
# GET /books # GET /books.json def index @books = Book.order(:id).page params[:page] end
<h1>Listing books</h1> <table> <thead> <tr> <th>Name</th> <th>Author</th> <th>Content</th> <th></th> <th></th> <th></th> </tr> </thead> <tbody> <% @books.each do |book| %> <tr> <td><%= book.name %></td> <td><%= book.author %></td> <td><%= book.content %></td> <td><%= link_to 'Show', book %></td> <td><%= link_to 'Edit', edit_book_path(book) %></td> <td><%= link_to 'Destroy', book, method: :delete, data: { confirm: 'Are you sure?' } %></td> </tr> <% end %> </tbody> </table> <%= paginate @books %> <br> <%= link_to 'New Book', new_book_path %>
8.执行命令bootstrap
rails g kaminari:views bootstrap
SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B:
certificate verify failed (OpenSSL::SSL::SSLError)
#自定义分页插件主题 #执行rails g kaminari:views bootstrap 时报错 做用:Ensure net/https uses OpenSSL::SSL::VERIFY_PEER to #verify SSL certificatesand provides certificate bundle in case OpenSSL cannot find one gem 'certified'
12.执行命令,生成kaminari 的view模板ruby
rails g kaminari:views bootstrap
13.启动程序,查看效果框架
14.更多信息请参考 ide
kaminari bootstrap-kaminari-views certified
15.项目源码