如何在 rails 3.2.3 中使用分页?

编程入门 行业动态 更新时间:2024-10-28 07:18:42
本文介绍了如何在 rails 3.2.3 中使用分页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我是 RoR 的新手,我想在我的应用程序中包含分页.

I'm new in RoR, and I want to include pagination in my application.

执行此任务的最佳方法是什么?请建议我.是否可以在 rails 3.2.3 中使用 will_paginate gem?

Which is the best way to perform this task? Please suggest me. Is it possible to use will_paginate gem in rails 3.2.3 ?

如果是,我应该包括在哪种方法中:

If yes, in which method I should include:

Post.where(:published => true).paginate(:page => params[:page]).order('id DESC') Post.page(params[:page]).order('created_at DESC')

推荐答案

是的,可以在 rails 3.2.3 应用程序中使用 will_paginate gem.

Yes, it is possible to use will_paginate gem in rails 3.2.3 applications.

代码将取决于每个操作将执行的内容.

And the code will depends on what each action will perform.

下面的代码通常使用 #index 方法,在您的 PostsController 中.

The code below usually goes on a #index method, in your PostsController.

@posts = Post.where(:published => true).paginate(:page => params[:page]).order('id DESC')

因此,在您的 posts/index.html.erb 视图文件中,您可以使用以下代码来显示分页链接:

So, in your posts/index.html.erb view file you can use the following code to display the pagination links:

<%= will_paginate @posts %>

更多推荐

如何在 rails 3.2.3 中使用分页?

本文发布于:2023-10-29 02:44:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1538496.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:分页   如何在   rails

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!