简体   繁体   English

Rails 4分页,will_paginate与Kaminari使用bootstrap3

[英]Rails 4 pagination, will_paginate vs. Kaminari using with bootstrap3

I understand Kaminari perform well with Rails3 reading this article: Rails 3 pagination, will_paginate vs. Kaminari , but how about with Rails4? 我理解Kaminari在阅读本文时表现良好: Rails 3分页,will_paginate与Kaminari ,但Rails4怎么样? Also, when stylizing them with Bootstrap3, which gem is easier solution? 另外,使用Bootstrap3对它们进行样式化时,哪种gem更容易解决?

In my experience, there is very little difference between Kaminari & Will Paginate - it's mainly a personal choice as to which you use (rather like Paperclip / Carrierwave or Mac / Windows ) 根据我的经验, KaminariWill Paginate之间几乎没有什么区别 - 它主要是你个人选择(比如Paperclip / CarrierwaveMac / Windows

In terms of compatibility, both gems work natively with Rails 4 在兼容性方面,这两个宝石本身都与Rails 4一起工作


Bootstrap 引导

In reference to Bootstrap, I think you're asking the wrong question 关于Bootstrap,我想你问的是错误的问题

Bootstrap is a CSS framework , which has no bearing on the backend functionality of your app Bootstrap是一个CSS框架 ,它与应用程序的后端功能无关

Bottom line is you're going to have to call the pagination methods from your controller, and so the differences of the systems will only be cosmetic. 最重要的是,您必须从控制器调用分页方法,因此系统的差异只是装饰性的。 If you use Bootstrap to stylize them, you'll have to do the same with either gem 如果你使用Bootstrap来对它们进行样式化,那么你必须对任何一个gem做同样的事情

So the choice is yours! 所以选择权归你的!

It is pretty easy to implement twitter bootstrap pagination with Kaminari . 使用Kaminari实现twitter bootstrap分页非常容易。 Just follow the steps below: 只需按照以下步骤操作:

  1. Add gem 'kaminari' to your GemFile . gem 'kaminari'添加到您的GemFile Run bundle install and restart rails server 运行bundle install并重启rails服务器
  2. Check the Kaminary themes - in your case you need the bootstrap3 theme 检查Kaminary主题 - 在您的情况下,您需要bootstrap3主题
  3. Run rails g kaminari:views bootstrap3 运行rails g kaminari:views bootstrap3

That's it. 而已。

Kaminari works fine for me with Rails 4.1.5 使用Rails 4.1.5,Kaminari对我来说很好

You can get it working with Bootstrap 3 by changing one line of code in the generated Bootstrap theme for Kaminari 您可以通过更改为Kaminari生成的Bootstrap主题中的一行代码来使用Bootstrap 3

In Views/Kaminari/_paginator.html.erb Views / Kaminari / _paginator.html.erb中

Change this line: <div class="pagination"><ul> 改变这一行: <div class="pagination"><ul>

To this: <ul class="pagination pagination-lg"> 对此: <ul class="pagination pagination-lg">

..and get rid of the div; ..摆脱div; just use the ul above --works fine for me. 只需使用上面的ul - 对我来说很好。


Here is the code for the whole partial: 这是整个部分的代码:

  <%= paginator.render do %>
  <ul class="pagination pagination-lg">
    <%= first_page_tag unless current_page.first? %>
    <%= prev_page_tag unless current_page.first? %>
    <% each_page do |page| %>
      <% if page.left_outer? || page.right_outer? || page.inside_window? %>
        <%= page_tag page %>
      <% elsif !page.was_truncated? %>
        <%= gap_tag %>
      <% end %>
    <% end %>
    <%= next_page_tag unless current_page.last? %>
    <%= last_page_tag unless current_page.last? %>
  </ul>
<% end %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM