Forum: Ruby How to print stuff in RTHML embedded code (equiv to php "ech

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.
Namor (Guest)
on 2006-03-07 05:51
(Received via mailing list)
Hi I got a very noob question which i cant understand why i cant do
things like this......


eg... inside.
helloworld.rhtml

<p>
   <%
        puts "hello"
        puts "world"
        puts "something something"
     %>
</p>


I know i can do this easily in php
<?php
echo "yes this works"
echo "testing 123"
echo "yes this works"
?>

Can someone help me?
Jonathan M. (Guest)
on 2006-03-07 07:49
(Received via mailing list)
It's a simple as:
   <%= "hello world!" %>

See also:
http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/cla...

Hope this helps,
Jonathan
Namor (Guest)
on 2006-03-07 08:31
(Received via mailing list)
hmmm
so means that for my program

 helloworld.rhtml

<p>
   <%= puts "hello" %>
   <%= puts "world" %>
   <%= puts "something something" %>
</p>

i have to do that?  that is obviously way harder to code..
and if it was in between a loop or something just say for debugging..
i got to close the loop and then bracket it..  then come back again?
man
there must be an easier way???
Sam K. (Guest)
on 2006-03-07 19:41
(Received via mailing list)
Namor wrote:
>         puts "world"
> ?>
>
> Can someone help me?

I'm not sure if this helps or even if it's good
I don't like to open and close with <%...%> repeatedly.
So I use the following.

<%
_erbout << "hello"
_erbout << "world"
_erbout << "something something"
%>

Sam
Logan C. (Guest)
on 2006-03-07 20:18
(Received via mailing list)
On Mar 7, 2006, at 1:28 AM, Namor wrote:

>
> i have to do that?  that is obviously way harder to code..
> and if it was in between a loop or something just say for debugging..
> i got to close the loop and then bracket it..  then come back again?
> man
> there must be an easier way???
>
>

Not exactly, you do this:
<p>
<%= "hello" %>
etc...
</p>

<%= is roughly analogous to "puts" or  "print"
kwatch (Guest)
on 2006-03-07 23:55
(Received via mailing list)
ERB doesn't allow you to use 'print' or 'puts' in eRuby script.
You can use print statement if you use Erubis instead of ERB.
Erubis is an implementation of eRuby which has some advantages over
ERB.
  http://rubyforge.org/projects/erubis/

For example, the following code is available with Eruby::PrintEruby
or Eruby::StdoutEruby class.

<p>
   <%
        print "hello\n"
        print "world\n"
        print "something something\n"
     %>
</p>

See doc/users-guide.html in the archive.
Namor (Guest)
on 2006-08-03 16:21
(Received via mailing list)
A better example would be

if i was to do some debugging
it would have to be

<% @articles.map { |x| %>
<%= x.name %>
<% } %>

instead of
<%= @articles.map { |x| echo x.name } %> ???

wouldnt that be so difficult to type out and to read as well?
Farrel L. (Guest)
on 2006-08-03 16:22
(Received via mailing list)
<%= @articles.join("<br\/>") %>
This topic is locked and can not be replied to.