Erb, the templating engine you're using in your views, has a few different ways of embedding ruby code inside templates.
When you put code inside <%= %>
blocks, erb evaluates the code inside and prints the value of the last statement in the HTML. Since .each
in ruby returns the collection you iterated over, the loop using <%= %>
attempts to print a string representation of the entire array.
When you put code inside <% %>
blocks, erb just evaluates the code, not printing anything. This allows you to do conditional statements, loops, or modify variables in the view.
You can also remove the puts
from puts t
. Erb knows to try to convert the last value it saw inside <%= %>
into a string for display.