Reputation: 16734
I am using acts_as_taggable_on, and everytime I want to display tags, I use the following:
7 #tags
8 %label Tags:
9 - @vendor.tags.each do |tag|
10 = link_to tag.name, tag_path(tag.name)
I have different models that all have tags, so ideally it would be a single helper that I pass the resource to...thinking something to do with using content_tag and a block....?
Upvotes: 1
Views: 105
Reputation: 7899
You can create a helper to display tags.
#tag_helper.rb
def display_tags(tags)
tag_string = ""
tags.each do |tag|
tag_string << link_to tag.name, tag_path(tag.name)
end
tag_string.html_safe
end
#view.html.erb
=display_tags(@vendor.tags)
Upvotes: 2