Forum: Ruby on Rails How to render from with <%%> ?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
34791e1d8c4def65f9b93294638a7e04?d=identicon&s=25 Joerg Diekmann (joergd)
on 2006-05-31 13:52
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 :-)
Ab14c50a93717a5bfd342496317975c4?d=identicon&s=25 Arie Kusuma Atmaja (Guest)
on 2006-05-31 13:59
(Received via mailing list)
Joerg Diekmann wrote:
>
> Joerg
>
> P.S. There is a good enough reason for me wanting to do this :-)
>
<% coll.each do |itm| -%>
   <%= itm.value %>
<% end -%>

--
Arie Kusuma Atmaja A.K.A Arie A.K.A ariekeren / YM! = riyari3
http://ariekusumaatmaja.wordpress.com
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?!
882cc23c77c5c6d27613c51396a02a0d?d=identicon&s=25 Stephen Bartholomew (Guest)
on 2006-05-31 14:02
(Received via mailing list)
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
1fba4539b6cafe2e60a2916fa184fc2f?d=identicon&s=25 unknown (Guest)
on 2006-05-31 14:08
(Received via mailing list)
Hi --

On Wed, 31 May 2006, Joerg Diekmann 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 :-)


David

--
David A. Black (dblack@wobblini.net)
* Ruby Power and Light, LLC (http://www.rubypowerandlight.com)
   > Ruby and Rails consultancy and training
* Author of "Ruby for Rails" from Manning Publications!
   > http://www.manning.com/black
C9c7a65848f13e2b1a226bbe43bc3672?d=identicon&s=25 Pete Yandell (pete)
on 2006-06-01 03:30
(Received via mailing list)
<%= coll.collect(&:value).join %>
6c27f78ab0eee78732ae54e8b8718b84?d=identicon&s=25 David Felstead (Guest)
on 2006-06-01 03:45
(Received via mailing list)
You can use the 'concat' method instead of 'puts':

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

Cheers,

-DF
This topic is locked and can not be replied to.