【问题标题】:How to paginate blog posts in a Rails application如何在 Rails 应用程序中对博客文章进行分页
【发布时间】:2009-08-05 20:16:59
【问题描述】:

我尝试了以下代码,但它不起作用

class BlogsController < ApplicationController
  def index
    #@entry_pages = Paginator.new(self, Entry.count, 10, params[:page])
    @entries = Entry.find(:all,
    #:limit => @entry_pages.items_per_page,
    #:offset => @entry_pages.current.offset,
    :order => 'entries.created_at DESC',
    :include => :user)
  end
end

这是博客视图

<h1>Recently updated blogs</h1>
<% @entries.each do |entry| %>
<p>
<%= link_to entry.user.username, entries_url(:user_id => entry.user) %><br />
'<%= entry.title %>' was posted <%= time_ago_in_words(entry.created_at) %> ago
</p>
<% end %>

我希望像这样对项目进行分页:

<<  [1][2][3]  >>

【问题讨论】:

    标签: ruby-on-rails ruby pagination


    【解决方案1】:

    试试will_paginate GEM。 它提供了为博客条目分页所需的所有功能。

    【讨论】:

      【解决方案2】:

      我可以推荐 paginating_find 插件。这是一个教程:

      http://www.igvita.com/2006/09/10/faster-pagination-in-rails/

      看起来它现在托管在 github.com 上:

      http://github.com/alexkwolfe/paginating_find/tree/master

      【讨论】:

        猜你喜欢
        • 2019-12-12
        • 2019-01-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多