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.

0

1 Answer 1

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

1
  • Great, thanks. I can't believe it was that simple.
    – Philip7899
    Nov 11, 2013 at 16:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.