2

In my rails view page, I have the following loop that should loop through my tag_list array and print each tag:

<%= @user.profile.tag_list.each do |tag| %>
    <%= tag %>
<% end %>

For some reason, it repeats the array after it prints each individual tag. For example, this array has two elements:

["ruby", "python"]

The output of the each method is "rubypython ruby,python". The output should just be "ruby python". How do I fix this?

By the way, I am using the acts-as-taggable-on gem to generate the tags, but that should not make a difference since it is just a simple array.

Philip7899
  • 4,599
  • 4
  • 55
  • 114

1 Answers1

3

you should remove the equals sign

<%= @user.profile.tag_list.each do |tag| %>

to

<% @user.profile.tag_list.each do |tag| %>

the embedded ruby is printing your each block after it's run, so you're getting results of .each being run as well as the tag

dax
  • 10,779
  • 8
  • 51
  • 86