Strings not displayed right

86 Views Asked by At

So, I have this which displays emails to a user.

OLD CODE FOR REFERENCE:

<%= for email in @emails 
    # print the name
    eml = email
    eml 
    puts "<br>"
end
%>

FIXED, WORKING, STABLE CODE:

<% for email in @emails  %>
    <%= email %>
    <br>
<% end %>
<%= puts @emails.inspect %>

As you can see, it was a problem of multiple line tag. Bazar that It would cause this problem, but not at all that it would cause A problem.

OLD:

And it is working great. One thing. So, EML is a ruby string with [email protected], but when it goes to display I get this on the rendered page: ["[email protected]"], so why is it doing that? Inspected it, it isn't a hash. Just a string. What is happening here?

1

There are 1 best solutions below

3
On

This syntax does not look quite right. If this is being rendered in a view using ERB, you probably want code that looks more like this:

<% @emails.each do |email| %>
    <%= email %><br />
<% end %>

The way you have that written is very C#-looking. In Ruby it is more common to use the methods attached to the object. Enumerable objects like arrays could be iterated through using the each method and a special structure in Ruby called a block.

http://www.ruby-doc.org/core-2.1.0/Array.html#method-i-each