4

I'm following the instructions at: http://agilewebdevelopment.com/plugins/acts_as_taggable_on_steroids to add the tag cloud to my view:

in the controller:

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

I also added the tag_cloud method as a helper method in the controller

and in the view:

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

However:

1) if I don't add the helper_method :tag_cloud in the controller I get a undefined method error for tag_cloud

2) if I do add the helper method I get: wrong number of arguments (2 for 0) on the same line 1 of my sample code above.

Suggestions?

SOLUTION I ended up not doing what I had as example code in the view.

Instead I did this:

<% @post.tags.each do |tag| %>
    <%= link_to( tag.name,tag,:class => "tag_cloud_item_link") %>
<% end %>

3 Answers 3

2

1.

Methods defined in the controller are not accessible to views unless you add (as you mention) the helper_method call.

2.

Your method tag_cloud that you've defined as a helper in your controller doesn't take any parameters, but you are trying to call tag_cloud with @tags, %w(css1...), & a block.

Your tag_cloud method will return an @tags instance variable and that's it.

From the post you've provided that you are working off of, did you include TagsHelper in your ApplicationHelper? I'm guessing that this defines a tag_cloud helper method that will accept the params that you are trying to pass in.

Sign up to request clarification or add additional context in comments.

2 Comments

Is everything else "working properly"? This seems like either a conflict of some sort or the plugin is not being loaded properly. Have you restarted your app since you installed the plugin (I know it sounds silly). Could you paste your full error?
reload and other things are working properly. I found a work around by using @tags = tag_cloud, then @tags.each. i will post more code & errors in a bit, thanks
1

I'm having the same issue. Just like the OP, Moving the "tag_cloud" helper method to the TagHelper seemed to get rid of some issue, but creates the "wrong number of arguments" error in the process.

cbrulak said he found a work arround. Can you update us and possibly send a PM to the "Acts-as-taggable-on" authors at https://github.com/mbleigh/acts-as-taggable-on

Comments

1

I arrived here because I wanted to define a method to use in the view. The simple answer was that it should have been defined in the model (e.g. conversation.rb file), and not in the helper.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.