带标签云的 Rails 分页

发布于 2024-10-18 20:14:26 字数 466 浏览 1 评论 0原文

我正在使用kaminari。它正在与一条链一起工作,我有 ActiveRecord::Relation 对象,但我不知道如何避免此错误。

代码在这里,使用 stackoverflow redactor 时遇到问题:/ http://pastie.org/1602799

问题是当我点击标签时,我收到错误

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

我看到了一些解决方案,但是它们用于 will_paginate 并且似乎已弃用,我如何正确地为 tag_cloud 进行分页?没有分页,一切都可以完美运行。

我尝试了 kaminari 和 will_paginate,都给我错误:(

im using kaminari. It's working with a chain and i have ActiveRecord::Relation object, but i cant figure out, howto avoid this error.

Code here, have trouble with stackoverflow redactor :/
http://pastie.org/1602799

Problem is when i hit tag, i got error

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

I seen some solution, but they for will_paginate and seems deprecated, how can i do pagination for tag_cloud properly? Without pagination everything work perfectly.

I try both kaminari and will_paginate, both give me errors :(

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

舂唻埖巳落 2024-10-25 20:14:26

这有效果吗?

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

Does this have any effect?

def tag
  @posts = Post.tagged_with(params[:id]).page(params[:page])
  @tags = Post.tag_counts_on(:tags)
  render :action => 'index'
end
灰色世界里的红玫瑰 2024-10-25 20:14:26

对于我们这些想要从馅饼中查看问题代码而无需来回切换的人来说。 (在小屏幕上很难看出解决方案是什么)

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

For those of us that want to see the questions code from the pastie without having to tab back and forth. (made it really hard to see what the solution was on a small screen)

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文