Extreme Ruby/Rails novice here: I’m trying to link_to a search action for each individual post contained in a block:
<% split_tags = post.tags.split(',') %> # returns ["food", "computers", "health"] %>
<p>Keywords: <%= split_tags.each {|tag| link_to(tag, front_search_tag_path(:tag => tag))}) %></p>
but all it returns is Keywords: ["food", "computers", "health"].
Shouldn’t .each iterate over the array and provide a link to each search_tag_path with the tag as a parameter?
Nope, #each just performs a block, it does not accumulate any data.
You have two options, use map to accumulate data:
Or output directly in the block:
Prints:
In your case this would be the following two options. I prefer the latter.