2011-02-24 43 views
2

即时通讯使用kaminari。它的工作与一个链,我有ActiveRecord :: Relation对象,但我无法弄清楚,如何避免这个错误。这里铁轨分页与标签云

代码,有计算器主编麻烦:/ http://pastie.org/1602799

问题是,当我打标签,我得到错误

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

我看到了一些解决方案,但他们为will_paginate和似乎过时,我如何正确地为tag_cloud做分页?没有分页,一切都很完美。

我尝试两个雷和will_paginate,既给我错误:(

回答

3

这是否有什么影响?

def tag 
    @posts = Post.tagged_with(params[:id]).page(params[:page]) 
    @tags = Post.tag_counts_on(:tags) 
    render :action => 'index' 
end 
+0

yeap,非常感谢,正是我需要的东西! – 2011-02-28 08:05:54

2

对于我们这些希望看到来自pastie问题代码,而不必(真的很难看到解决方案是在小屏幕上)

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