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 :-) -- Posted via http://www.ruby-forum.com/.
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? > > 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?!
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 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? > > Joerg > > P.S. There is a good enough reason for me wanting to do this :-) >
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
Joerg, I haven''t found a good way to do what you want. I think just separate code blocks is the cleanest. <%coll.each do |itm|%> <%=itm.value%> <%end%> It''s ugly, but more readable (to a simpleton like me) than <% coll.each {|itm| _erbout << itm.value } %> Marcus -----Original Message----- From: rails-bounces@lists.rubyonrails.org [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of dblack@wobblini.net Sent: Wednesday, May 31, 2006 5:07 AM To: rails@lists.rubyonrails.org Subject: Re: [Rails] How to render from with <%%> ? 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 _______________________________________________ Rails mailing list Rails@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails
Hi -- On Wed, 31 May 2006, Marcus Blankenship wrote:> Joerg, I haven''t found a good way to do what you want. I think just > separate code blocks is the cleanest. > > <%coll.each do |itm|%> > <%=itm.value%> > <%end%> > > It''s ugly, but more readable (to a simpleton like me) than <% coll.each > {|itm| _erbout << itm.value } %>Of course it is, but Joerg specifically asked for a way to do this without using <%= %>. David> Marcus > > -----Original Message----- > From: rails-bounces@lists.rubyonrails.org > [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of > dblack@wobblini.net > Sent: Wednesday, May 31, 2006 5:07 AM > To: rails@lists.rubyonrails.org > Subject: Re: [Rails] How to render from with <%%> ? > > 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 > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- 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
<%= coll.collect(&:value).join %> On 31/05/2006, at 9:52 PM, 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? > > Joerg > > P.S. There is a good enough reason for me wanting to do this :-) > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
You can use the ''concat'' method instead of ''puts'': <% coll.each do |itm| concat(itm.value, binding) end %> Cheers, -DF On 5/31/06, Joerg Diekmann <joergd@pobox.com> 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? > > Joerg > > P.S. There is a good enough reason for me wanting to do this :-) > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >