views:

39

answers:

1

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?

+2  A: 

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.

theIV
yes, I did include the taghelper in the apphelper.
cbrulak
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?
theIV
cbrulak