ASP's Response.Write for ERb

Subscribe to ASP's Response.Write for ERb 2 posts, 2 voices

 
Avatar Scott 7 posts

Back with good ‘ol ASP, you could do something like this:

<%
For Each Animal in Barn
  Response.Write Animal.Name
End
%>

but with ERb, I seem to have to do this:

<% for Animal in Barn %>
  <%= Animal.Name %>
<% end %>

is there any way to do something like this with ERb:

<% 
for Animal in Barn
  puts Animal.Name
end 
%>

puts doesn’t seem to do the trick.

 
Avatar Brian Eng 49 posts

You could do something like

<% for animal in barn; concat(animal.name, binding); end %>

But not recommended. What you’ve got in your second example is the preferred approach. Kinda nice actually. There’s a clear distinction between evaluated Ruby code and what you’re going to output to the view.