ARTLoe ARTLoe - 3 months ago 9
Ruby Question

How to use split or join to split a tag links

In

users/_form.html.erb
there is a list of interests which are spaced out with a space, e.g. "comic superhero happy". When I save the user's interests they appear in the users/show.html.erb file as one long link as in the attached image.

How do I separate the a tag links?

I tried this code to split the the links but had no success:

<%= raw @user.tag_list.map { |t| link_to t, tag_path(t) }.join(" ") %>

>> @user.tag_list
=> ["comic superhero happy"]

trying to get this result:
>> @user.tag_list
=> ["comic" "superhero" "happy"]


enter image description here

Answer
tags =  @user.tag_list.split(" ").map do |t|
  link_to t, tag_path(t)
end