ARTLoe ARTLoe - 1 month ago 7x
Ruby Question

How to use split or join to split a tag links


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 { |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

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