How to render from with <%%>?


#1

I have a loop that I iterate through in my view.

<%
coll.each do |itm|
puts(itm.value)
end
%>

How do I render the itm.value without using a <%= %> tag? Should puts
not work?

Joerg

P.S. There is a good enough reason for me wanting to do this :slight_smile:


#2

Joerg D. wrote:

Joerg

P.S. There is a good enough reason for me wanting to do this :slight_smile:

<% coll.each do |itm| -%>
<%= itm.value %>
<% end -%>


Arie Kusuma A. A.K.A Arie A.K.A ariekeren / YM! = riyari3


Let’s build Ruby Indonesia stronger
http://groups.yahoo.com/groups/id-ruby # Indonesia Ruby Society

500 baris di PHP dkk VS 1 baris di Ruby dkk
300 baris di Java dkk VS 1 baris di Ruby dkk
Macih ngotot pake (as|ph)p? haree geneee???
Buat yang pake Ruby, nyesel kan lu pake Ruby!!! kenapa ga dari dulu?!


#3

You can’t use puts in views.

What is it you’re trying to do? You’ll have to give us the good enough
reason i think :0)

Steve


#4

<%= coll.collect(&:value).join %>


#5

You can use the ‘concat’ method instead of ‘puts’:

<%
coll.each do |itm|
concat(itm.value, binding)
end
%>

Cheers,

-DF


#6

Hi –

On Wed, 31 May 2006, Joerg D. wrote:

I have a loop that I iterate through in my view.

<%
coll.each do |itm|
puts(itm.value)
end
%>

How do I render the itm.value without using a <%= %> tag? Should puts
not work?

puts doesn’t append its arguments to the _erbout variable, which is
where erb accumulates its output.

You could do:

<% coll.each {|itm| _erbout << itm.value } %>

or something like that, though that’s really what <%= %> is for :slight_smile:

David


David A. Black (removed_email_address@domain.invalid)