I've noticed that pagination gems like mislav-will_paginate
are quite popular. Is this because Rails does not have a built-in pagination solution or because the built-in solution is not very good?
我注意到像mislav-will_paginate这样的分页宝石很受欢迎。这是因为Rails没有内置的分页解决方案,还是因为内置的解决方案不是很好?
4 个解决方案
#1
28
In Rails 2.0 the pagination ability of ActionController was removed and turned into a plugin for backwards compatibility called 'classic_pagination'. However, from my searches for a pagination solution for myself the consensus seems to be that using 'classic_pagination' is not optimal.
在Rails 2.0中,ActionController的分页功能被删除,并变成了一个名为'classic_pagination'的向后兼容插件。但是,从我为自己搜索分页解决方案来看,共识似乎是使用'classic_pagination'并非最佳。
After watching a couple of podcasts and after several recommendations I opted to try the will_paginate plugin and haven't looked back. It's fast, easy to use and well-maintained.
在观看了几个播客之后,经过多次推荐后,我选择尝试使用will_paginate插件并且没有回头看。它快速,易于使用且维护良好。
I believe that even V2 of Searchlogic recommends its use.
我相信即使是Searchlogic的V2也推荐使用它。
#2
15
If you are using Rails 3 Kaminari plugin will be very handy for pagination. Github Railscasts
如果你使用Rails 3 Kaminari插件将非常方便分页。 Github Railscasts
#3
8
Rails has built-in pagination, but it's a simple module and not suitable for all needs. Unless you have specific pagination needs in mind though, it should suit most purposes.
Rails具有内置分页功能,但它是一个简单的模块,并不适合所有需求。除非你有特定的分页需求,否则它应该适合大多数目的。
Here's a good article on how to use Rails pagination
这是一篇关于如何使用Rails分页的好文章
#4
3
I'd recommend searchlogic. It has pagination built in and many other nices things.
我推荐searchlogic。它内置了分页和许多其他的东西。
- Easy filtering
- 轻松过滤
- Pagination
- 分页
- Sorting
- 排序
And.. for all of that nice helpers.
而且..对于所有那些好帮手。
Code says more than thousand words (dont get confused by the HAML example, you can use normal erb templates if you prefer them, the code/structure is the same):
代码说超过千字(不要被HAML示例搞糊涂,如果你喜欢它们,你可以使用普通的erb模板,代码/结构是相同的):
Controller:
控制器:
def index
@search = User.new_search(params[:search])
@users, @users_count = @search.all, @search.count
end
Pagination stuff in the view:
视图中的分页内容:
== Per page: #{per_page_select}
== Page: #{page_select}
Sort as/by in view:
在视图中排序为/:
- unless @users_count.zero?
%table
%tr
%th= order_by_link :account => :name
%th= order_by_link :first_name
%th= order_by_link :last_name
%th= order_by_link :email
- @users.each do |user|
%tr
%td= user.account? ? user.account.name : "-"
%td= user.first_name
%td= user.last_name
%td= user.email
Easy, simple and quick filters:
简单,简单,快速的过滤器:
- form_for @search do |f|
- f.fields_for @search.conditions do |users|
= users.text_field :first_name_contains
= users.date_select :created_after
- users.fields_for users.object.orders do |orders|
= orders.select :total_gt, (1..100)
= f.submit "Search"
And everything works together, so changing a page and then the sorting, and adding a filter works without losing any of the other settings :).
一切都在一起工作,所以更改页面,然后排序,添加过滤器工作,而不会丢失任何其他设置:)。
All you need is in your environment.rb:
您所需要的只是在您的环境中.rb:
config.gem "searchlogic"
and install it with: rake gems:install
并安装它:rake gems:install
Also checkout the online example
还要查看在线示例
#1
28
In Rails 2.0 the pagination ability of ActionController was removed and turned into a plugin for backwards compatibility called 'classic_pagination'. However, from my searches for a pagination solution for myself the consensus seems to be that using 'classic_pagination' is not optimal.
在Rails 2.0中,ActionController的分页功能被删除,并变成了一个名为'classic_pagination'的向后兼容插件。但是,从我为自己搜索分页解决方案来看,共识似乎是使用'classic_pagination'并非最佳。
After watching a couple of podcasts and after several recommendations I opted to try the will_paginate plugin and haven't looked back. It's fast, easy to use and well-maintained.
在观看了几个播客之后,经过多次推荐后,我选择尝试使用will_paginate插件并且没有回头看。它快速,易于使用且维护良好。
I believe that even V2 of Searchlogic recommends its use.
我相信即使是Searchlogic的V2也推荐使用它。
#2
15
If you are using Rails 3 Kaminari plugin will be very handy for pagination. Github Railscasts
如果你使用Rails 3 Kaminari插件将非常方便分页。 Github Railscasts
#3
8
Rails has built-in pagination, but it's a simple module and not suitable for all needs. Unless you have specific pagination needs in mind though, it should suit most purposes.
Rails具有内置分页功能,但它是一个简单的模块,并不适合所有需求。除非你有特定的分页需求,否则它应该适合大多数目的。
Here's a good article on how to use Rails pagination
这是一篇关于如何使用Rails分页的好文章
#4
3
I'd recommend searchlogic. It has pagination built in and many other nices things.
我推荐searchlogic。它内置了分页和许多其他的东西。
- Easy filtering
- 轻松过滤
- Pagination
- 分页
- Sorting
- 排序
And.. for all of that nice helpers.
而且..对于所有那些好帮手。
Code says more than thousand words (dont get confused by the HAML example, you can use normal erb templates if you prefer them, the code/structure is the same):
代码说超过千字(不要被HAML示例搞糊涂,如果你喜欢它们,你可以使用普通的erb模板,代码/结构是相同的):
Controller:
控制器:
def index
@search = User.new_search(params[:search])
@users, @users_count = @search.all, @search.count
end
Pagination stuff in the view:
视图中的分页内容:
== Per page: #{per_page_select}
== Page: #{page_select}
Sort as/by in view:
在视图中排序为/:
- unless @users_count.zero?
%table
%tr
%th= order_by_link :account => :name
%th= order_by_link :first_name
%th= order_by_link :last_name
%th= order_by_link :email
- @users.each do |user|
%tr
%td= user.account? ? user.account.name : "-"
%td= user.first_name
%td= user.last_name
%td= user.email
Easy, simple and quick filters:
简单,简单,快速的过滤器:
- form_for @search do |f|
- f.fields_for @search.conditions do |users|
= users.text_field :first_name_contains
= users.date_select :created_after
- users.fields_for users.object.orders do |orders|
= orders.select :total_gt, (1..100)
= f.submit "Search"
And everything works together, so changing a page and then the sorting, and adding a filter works without losing any of the other settings :).
一切都在一起工作,所以更改页面,然后排序,添加过滤器工作,而不会丢失任何其他设置:)。
All you need is in your environment.rb:
您所需要的只是在您的环境中.rb:
config.gem "searchlogic"
and install it with: rake gems:install
并安装它:rake gems:install
Also checkout the online example
还要查看在线示例