質問

次のコードを試しましたが、動作しません

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]  >>
役に立ちましたか?

解決

will_paginate GEMを試してください。 ブログエントリのページ分割に必要なすべての機能を提供します。

他のヒント

paginating_find プラグインを推奨できます。チュートリアルは次のとおりです。

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

現在github.comでホストされているように見えます:

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top