2

カミナリを使っています。チェーンで動作しており、ActiveRecord::Relation オブジェクトがありますが、このエラーを回避する方法がわかりません。

ここのコード、stackoverflow redactor に問題があります:/ http://pastie.org/1602799

問題は、タグをヒットしたときにエラーが発生したことです

undefined method `current_page' for #<ActiveRecord::Relation:0x9ee7cb8>

いくつかの解決策を見ましたが、それらは will_paginate 用であり、非推奨のようです。tag_cloud のページネーションを適切に行うにはどうすればよいですか? ページネーションがなければ、すべてが完全に機能します。

kaminari と will_paginate の両方を試してみましたが、どちらもエラーが発生しました :(

4

2 に答える 2

3

これは何か効果がありますか?

def tag
  @posts = Post.tagged_with(params[:id]).page(params[:page])
  @tags = Post.tag_counts_on(:tags)
  render :action => 'index'
end
于 2011-02-27T15:56:53.597 に答える
2

タブを前後に動かさずにパスティからの質問コードを見たいと思っている私たちのために。(小さな画面で解決策が何であるかを確認するのが非常に困難になりました)

def index
    @posts = Post.page(params[:page]).per(5)
    tag_cloud
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @posts }
    end
  end
  def tag
    @posts = Post.tagged_with(params[:id])
    @tags = Post.tag_counts_on(:tags)
    render :action => 'index'  
  end

  def tag_cloud
      @tags ||= Post.tag_counts_on(:tags)
  end

View

%h1 Listing posts
-tag_cloud(@tags, %w(css1 css2 css3 css4)) do |tag, css_class|
  = link_to tag.name, { :action => :tag, :id => tag.name }, :class => css_class
于 2011-12-02T19:43:11.123 に答える