views:

250

answers:

4

I have the tag functionality working ok but can't generate a tag_cloud

in my controller:

def tag_cloud 
@tags = Article.tag_counts # returns all the tags used

in the view:

<% tag_cloud Article.tag_counts.sort { |x, y| x.name <=> y.name }, %w(x-small small normal large x-large) do |tag, css_class| %>
<%= link_to tag.name, tag_url( :tag => tag.name ), :class => css_class %>
<% end %></code

I always get a undefined method error for tag_cloud

A: 

You can't call controller methods from the view. Try putting it in a model or passing it to the view from the controller.

If this isn't helpful enough, try editing the question and including more details such as the full definition of tag_cloud, explain why you're setting @tag but not using it, etc.

MarkusQ
A: 

That code doesn't look like it'll do all you want, but to remedy the undefined method error, the proper place for auxiliary methods for views is in the helper, so move the method tag_cloud there instead.

You'll find it in app/helpers/controllername_helper.rb.

Ian Terrell
A: 

tag_cloud defined in module TagsHelper. You need to include it in corresponding helper:

module ApplicationHelper
  include TagsHelper
end

Also there is no need in controllers tag_cloud

A: 

sergeykish.com is correct, you just need to include the helper in /app/helpers/application_helper.rb

module ApplicationHelper
  include TagsHelper
end
Paul Groves