次のヘルパーメソッドが与えられます。
def link_tags(collection)
tags = collection.split(',')
tags.map.each do |tag|
if tag == tags.last
content_tag(:a, tag, href: tags_filter_post_path(tag) )
else
content_tag(:a, tag, href: tags_filter_post_path(tag) ) + ', '
end
end.reduce(:<<)
end
これを少しリファクタリングするにはどうすればよいですか?
編集:リファクタリング後の最終的なコードが提案されました。
def link_tags(collection)
collection.split(',').collect do |tag|
link = ""
link += link_to tag, tags_filter_post_path(tag)
end.join(', ').html_safe
end