I was reading the erb section of Progamming Ruby this morning. WRT <
%, I note that they say, "Insert the given Ruby code at this point in
the generated program. If it outputs anything include this output in
the result."
The last sentence left me a bit confused. Surely I can''t do something
like:
<% print(''Hello, world!'') %>
I did some Googling and came across:
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/2771
which seemed to say that''s exactly what I could do. However, of
course when I tried it, it didn''t work. That''s not too
surprising to
me since it was always my understanding that ''print'' directed
output
to the console and not to standard out.
Anyway, can someone clear the confusion for me. If there is a way to
use ''print'' as is suggested (or something similar),
I''d sure like to
know about it as it would come in handy every once in a while.
Thanks for any input.
... doug
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
<% print("hello world!") %> will print to the console window
that your
server is running in.
<%= "Hello World" %> Will print to the browser.
print in the above statement should print whatever argument you pass in it
to the browser AND to the console.
<%= is the output block, and <% is just an evaluation block.
On Dec 19, 2007 10:52 AM, doug
<ddjolley-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> I was reading the erb section of Progamming Ruby this morning. WRT <
> %, I note that they say, "Insert the given Ruby code at this point in
> the generated program. If it outputs anything include this output in
> the result."
>
> The last sentence left me a bit confused. Surely I can''t do
something
> like:
>
> <% print(''Hello, world!'') %>
>
> I did some Googling and came across:
>
> http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/2771
>
> which seemed to say that''s exactly what I could do. However, of
> course when I tried it, it didn''t work. That''s not too
surprising to
> me since it was always my understanding that ''print''
directed output
> to the console and not to standard out.
>
> Anyway, can someone clear the confusion for me. If there is a way to
> use ''print'' as is suggested (or something similar),
I''d sure like to
> know about it as it would come in handy every once in a while.
>
> Thanks for any input.
>
> ... doug
> >
>
--
Ryan Bigg
http://www.frozenplague.net
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
> <%= is the output block, and <% is just an evaluation block.Yes. That''s the way I have always understood it. So, if that''s the case, WRT ''<%'', what does the sentence, "If it outputs anything, include this output in the result" in Programming Ruby mean? Thanks for the input. ... doug --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
It''s saying that if whatever is contained within <%= and %> outputs anything at all, that output will be displayed on the page. Say I had a method called funky_stuff in the application_helper: def funky_stuff "<b><i><u><font color=''#00ff00''>BRIGHT GREEN</font><font color=''#ff00ff''>BRIGHT PINK</font></u></i></b>" end To use this method I would use <%= funky_stuff %> if I did <% funky_stuff %> the output would be supressed. On Dec 19, 2007 11:11 AM, doug <ddjolley-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > <%= is the output block, and <% is just an evaluation block. > > Yes. That''s the way I have always understood it. So, if that''s the > case, WRT ''<%'', what does the sentence, "If it outputs anything, > include this output in the result" in Programming Ruby mean? > > Thanks for the input. > > ... doug > > >-- Ryan Bigg http://www.frozenplague.net --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
The wording in the book is confusing you because you are only thinking
about erb in the context of RoR.
Here is a slightly more detailed explanation:
<% print ''foo'' %> prints ''foo'' to
stdout connected to the process that
is interpreting the erb, but does not get included in the output
generated by the template.
<%= ''foo'' %> inserts ''foo'' into the
output generated by template. Where
this output ends up depends on what the application interpreting the erb
does with the output, which in the case of rails is the browser.
However, an application could write it to a file, print it to stderr, etc.
For example:
require ''erb''
template = ERB.new "The value is: <% print ''foo''
%>"
puts template.result
results in "fooThe value is:" because foo is printed to stdout
immediately, but the results are stored then printed to stdout via puts.
require ''erb''
template = ERB.new "The value is: <%= ''foo''
%>"
puts template.result
results in "The value is: foo" because foo is inserted into the output
from the template then printed to stdout via puts.
HTH,
-Bill
Ryan Bigg wrote:> <% print("hello world!") %> will print to the console
window that your
> server is running in.
>
> <%= "Hello World" %> Will print to the browser.
>
> print in the above statement should print whatever argument you pass
> in it to the browser AND to the console.
>
> <%= is the output block, and <% is just an evaluation block.
>
> On Dec 19, 2007 10:52 AM, doug
<ddjolley-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
> <mailto:ddjolley-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> wrote:
>
>
> I was reading the erb section of Progamming Ruby this morning. WRT
<
> %, I note that they say, "Insert the given Ruby code at this point
in
> the generated program. If it outputs anything include this output in
> the result."
>
> The last sentence left me a bit confused. Surely I can''t do
something
> like:
>
> <% print(''Hello, world!'') %>
>
> I did some Googling and came across:
>
> http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/2771
>
> which seemed to say that''s exactly what I could do. However,
of
> course when I tried it, it didn''t work. That''s not
too surprising to
> me since it was always my understanding that ''print''
directed output
> to the console and not to standard out.
>
> Anyway, can someone clear the confusion for me. If there is a way to
> use ''print'' as is suggested (or something similar),
I''d sure like to
> know about it as it would come in handy every once in a while.
>
> Thanks for any input.
>
> ... doug
>
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Try this again minus the bad formatting :)
The wording in the book is confusing you because you are only thinking
about erb in the context of RoR.
Here is a slightly more detailed explanation:
<% print ''foo'' %> prints ''foo'' to
stdout connected to the process that
is interpreting the erb, but does not get included in the output
generated by the template.
<%= ''foo'' %> inserts ''foo'' into the
output generated by template. Where
this output ends up depends on what the application interpreting the erb
does with the output, which in the case of rails is the browser.
However, an application could write it to a file, print it to stderr, etc.
For example:
require ''erb''
template = ERB.new "The value is: <% print ''foo''
%>"
puts template.result
results in "fooThe value is:" because foo is printed to stdout
immediately, but the results are stored then printed to stdout via puts.
require ''erb''
template = ERB.new "The value is: <%= ''foo''
%>"
puts template.result
results in "The value is: foo" because foo is inserted into the output
from the template then printed to stdout via puts.
HTH,
-Bill
Ryan Bigg wrote:> <% print("hello world!") %> will print to the console
window that your
> server is running in.
>
> <%= "Hello World" %> Will print to the browser.
>
> print in the above statement should print whatever argument you pass
> in it to the browser AND to the console.
>
> <%= is the output block, and <% is just an evaluation block.
>
> On Dec 19, 2007 10:52 AM, doug
<ddjolley-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
> <mailto:ddjolley-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> wrote:
>
>
> I was reading the erb section of Progamming Ruby this morning. WRT
<
> %, I note that they say, "Insert the given Ruby code at this point
in
> the generated program. If it outputs anything include this output in
> the result."
>
> The last sentence left me a bit confused. Surely I can''t do
something
> like:
>
> <% print(''Hello, world!'') %>
>
> I did some Googling and came across:
>
> http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/2771
>
> which seemed to say that''s exactly what I could do. However,
of
> course when I tried it, it didn''t work. That''s not
too surprising to
> me since it was always my understanding that ''print''
directed output
> to the console and not to standard out.
>
> Anyway, can someone clear the confusion for me. If there is a way to
> use ''print'' as is suggested (or something similar),
I''d sure like to
> know about it as it would come in handy every once in a while.
>
> Thanks for any input.
>
> ... doug
>
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
> The wording in the book is confusing you because you are only > thinking about erb in the context of RoR.OK. I get it now. It did have me scratching my head. Thanks for the input. ... doug --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---