【问题标题】:LocalJumpError, Tag Cloud with acts_as_taggable on Rails 2.3.5LocalJumpError,在 Rails 2.3.5 上使用acts_as_taggable 标记云
【发布时间】:2009-12-19 15:57:49
【问题描述】:

我正在使用带有 rails 2.3.5 的 acts_as_taggable_on_steroids 插件来构建标签云,但我不熟悉他们的视图循环的语法。我也找不到任何解释该循环的 ruby​​ 文档。

当我运行下面的代码时,我得到了这个“no block given”错误。

LocalJumpError in Tags#index
Showing app/views/tags/index.html.erb where line #10 raised:
no block given 

我认为我需要将 tag_cloud 方法添加到我的 routes.rb 文件中,但这并没有解决问题。

控制器:

class PostController < ApplicationController
    def tag_cloud
      @tags = Post.tag_counts
    end
  end

查看:

  <% tag_cloud @tags, %w(css1 css2 css3 css4) do |tag, css_class| %>
    <%= link_to tag.name, { :action => :tag, :id => tag.name }, :class => css_class %>
  <% end %>

【问题讨论】:

    标签: ruby-on-rails acts-as-taggable


    【解决方案1】:

    看起来插件中的 TagsHelper 没有被包括在内,尽管我将它包含在 ApplicationHelper 中。

    我刚刚将函数 tag_cloud 复制到了我的 TagsHelper 中,它工作了。

    为什么我不明白那个循环是因为它是一个方法调用,带有一个链接到它的循环。 可以这样想

    <% tag_cloud( @tags, %w(css1 css2 css3 css4) ) do |tag, css_class| %>
      <%= link_to tag.name, tags_path(tag), :class => css_class %>
    <% end %>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多