Search code examples
ruby-on-railsparametersrouteslink-toacts-as-taggable-on

Pass params on index_path route


I'm having a helper for displaying the tags of a post

# Show action
%p Tags #{ link_tags @post }

# Helper
def link_tags post
  raw post.tag_list.map{ |t| 
    link_to t, posts_path(tag: t.name)
  }.join(', ')
end

However I'm getting an error on screen

undefined method `name' for "ruby":String

How can I fix this? As a side note the code on my sidebar (where I list all post-tags) where I tried to copy from works fine

- tag_cloud Post.tag_counts, %w(tag) do |tag, css_class|
    = link_to tag.name, posts_path(tag: tag.name), :class => css_class

Solution

  • post.tag_list will give you an array of tags as strings.

    What you are looking for is probably post.tags which should return an array of ActsAsTaggableOn objects.

    Here you have tutorial about tags on posts