思路:will_paginate是一个做分页的gem,但是风格不太好看,使用will_paginate-bootstrap这个gem做一个带有bootstrap样式的分页
Gemfile添加gem
gem 'will_paginate-bootstrap'
bundle install
在controller中:
@users = User.page(params[:page] || 1).per_page(params[:per_page] || 10).order("id desc")
在view中:
<%= will_paginate @users, renderer: BootstrapPagination::Rails %>
在config/intializers/下建立文will_paginate.rb添加如下内容:
WillPaginate::ViewHelpers.pagination_options[:previous_label ] = "前一页"
WillPaginate::ViewHelpers.pagination_options[:next_label ] = "后一页"
这样页面中就会显示中文的前一页和后一页