如何使用 ruby on rails 对记录进行分页? [英] How do I do paging of records with ruby on rails?
问题描述
我想用 ruby on rails 对数据列表进行分页.基本上,我想一次只显示 20 条记录,带有下一步和后退按钮.显示页码链接会很好,但不是必需的.
这样的东西会很好:
<<上一个 1 2 3 4 5 ... 下一个 >>
是否有内置的方法可以在 ruby on rails(或我可以添加的东西)中执行此操作,因此我不必自己编写?
有一个插件 will_paginate 可用于在 RoR 中无缝地进行分页.找到以下链接.他们可能会有所帮助.
http://nasir.wordpress.com/2007/10/31/pagination-in-ruby-on-rails-using-will_paginate-plugin/
https://github.com/mislav/will_paginate/wiki/>
https://github.com/mislav/will_paginate/wiki/simple-search
http://blog.railsspace.com/past/2008/1/31/railsspace_will_paginate/
此外,我相信关注 Ryan Bates 的 railscast 将是一个很好的理解来源.所有的 rails casts 都非常好,可以让您深入了解基础知识.http://railscasts.com/episodes/51-will-paginate
I want to do paging of lists of data with ruby on rails. Basically, I want to show only 20 records at a time, with next and back buttons. It would be nice, but not required, to show links for the page numbers.
Something like this would be nice:
<< Previous 1 2 3 4 5 ... Next >>
Is there a built in way to do this in ruby on rails (or something I can add) so I don't have to write this myself?
There is a plugin will_paginate that can be used to do pagination seamlessly in RoR. Find following links. They might be of some help.
http://nasir.wordpress.com/2007/10/31/pagination-in-ruby-on-rails-using-will_paginate-plugin/
https://github.com/mislav/will_paginate/wiki/
https://github.com/mislav/will_paginate/wiki/simple-search
http://blog.railsspace.com/past/2008/1/31/railsspace_will_paginate/
Also I am sure that following railscast by Ryan Bates is going to be an excellent source of understanding. All rails casts are really good and give you deep understanding of basics. http://railscasts.com/episodes/51-will-paginate
这篇关于如何使用 ruby on rails 对记录进行分页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!