twitter-bootstrap Rails 4 分页,will_paginate 与 Kaminari 与 bootstrap3 一起使用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21426136/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 19:52:26  来源:igfitidea点击:

Rails 4 pagination, will_paginate vs. Kaminari using with bootstrap3

ruby-on-railstwitter-bootstrappaginationwill-paginatekaminari

提问by tkymtk

I understand Kaminariperform well with Rails3 reading this article: Rails 3 pagination, will_paginate vs. Kaminari, but how about with Rails4? Also, when stylizing them with Bootstrap3, which gem is easier solution?

Kaminari阅读这篇文章,我理解Rails3 表现良好:Rails 3 pagination, will_pagination vs. Kaminari,但是 Rails4 怎么样?另外,当使用 Bootstrap3 对它们进行样式化时,哪个 gem 更容易解决?

回答by Richard Peck

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/ Carrierwaveor Mac / Windows)

根据我的经验,Kaminari&之间的区别很小Will Paginate- 这主要是您使用的个人选择(而不是Paperclip/CarrierwaveMac / Windows

In terms of compatibility, both gems work natively with Rails 4

在兼容性方面,这两个 gem 都可以与 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!

所以选择权在你!

回答by gotqn

It is pretty easy to implement twitter bootstrap pagination with Kaminari. Just follow the steps below:

使用Kaminari. 只需按照以下步骤操作:

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

That's it.

而已。

回答by Jordan

Kaminari works fine for me with Rails 4.1.5

Kaminari 使用 Rails 4.1.5 对我来说很好用

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; just use the ul above --works fine for me.

..并摆脱div;只需使用上面的 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 %>