[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

How to print stuff in RTHML embedded code (equiv to php "echo")??

Namor

3/7/2006 3:47:00 AM

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?

7 Answers

Namor

3/7/2006 6:24:00 AM

0

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???

Namor

3/7/2006 6:27:00 AM

0

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?

Jonathan Maasland

3/7/2006 8:07:00 AM

0

It's a simple as:
<%= "hello world!" %>

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

Hope this helps,
Jonathan

Namor wrote:
> 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?
>

Farrel Lifson

3/7/2006 8:09:00 AM

0

<%= @articles.join("<br\/>") %>

On 3/7/06, Namor <john.wcl@gmail.com> wrote:
> 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?
>
>
>


Sam Kong

3/7/2006 5:34:00 PM

0


Namor wrote:
> 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?

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 Capaldo

3/7/2006 6:15:00 PM

0


On Mar 7, 2006, at 1:28 AM, Namor wrote:

> 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???
>
>

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

<%= is roughly analogous to "puts" or "print"



Makoto Kuwata

3/7/2006 9:50:00 PM

0

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/projec...

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.


> 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?

--
regards,
kwatch