How to output something from within <% %> tags?

simple question: how do I output something from within <% %> tags? e.g.
like ‘echo’ in PHP. I thought it would be ‘puts’ or ‘print’ but neither
seems to work. right now I always close the %> and open a <%= which is
tedious.

You would use <% render :text => “whatever you want to write” %> but I’m
not
sure how that would be less tedious than <%= “whatever you want to
write” %>

Filip G. wrote:

simple question: how do I output something from within <% %> tags? e.g.
like ‘echo’ in PHP. I thought it would be ‘puts’ or ‘print’ but neither
seems to work. right now I always close the %> and open a <%= which is
tedious.

From API docs:
concat(string, binding)

The regular puts and print are outlawed in eRuby. Itâ??s recommended to
use the <%= “hello” %> form instead of print “hello”. If you absolutely
must use a method-based output, you can use concat. Itâ??s used like this:
<% concat “hello”, binding %>. Notice that it doesnâ??t have an equal sign
in front. Using <%= concat “hello” %> would result in a double hello.

Simo
Addsw.it

Simo Gal wrote:

From API docs:
concat(string, binding)

The regular puts and print are outlawed in eRuby. Itâ??s recommended to
use the <%= “hello” %> form instead of print “hello”. If you absolutely
must use a method-based output, you can use concat. Itâ??s used like this:
<% concat “hello”, binding %>. Notice that it doesnâ??t have an equal sign
in front. Using <%= concat “hello” %> would result in a double hello.

Thanx, that works but the “, binding” part makes it bad. I tried to put
this in application_helper.rb

def echo(str)
concat(str, binding)
end

but that generates an error

undefined local variable or method `_erbout’ for
#<#Class:0x384b968:0x384b548>

Sometimes RoR annoys the hell out of me. Why would they deliberately
‘outlaw’ a most basic function?

Clint P. wrote:

You would use <% render :text => “whatever you want to write” %> but I’m
not
sure how that would be less tedious than <%= “whatever you want to
write” %>

Thanx but that doesn’t work; render :text only works from within the
controller and it won’t render anything else anymore. I just need a
command to echo stuff within a view.

With an echo command I could do this:

<%
code
echo “whatever you want to write”
more code
%>

Whereas now I have to do this:

<%
code
%>
<%= “whatever you want to write” %>
<%
more code
%>

And that is very tedious.

An echo command is so basic, surely RoR has this?

It is simple. Where would puts output to?
My guess is it would go to stdout, so to the webrick console?

 Erik.

Filip G. schreef:

Filip G. wrote:

#<#Class:0x384b968:0x384b548>
That’s because if you put it in a helper method, the binding is picked
up from inside the helper method, which knows nothing about the
variables local to the erb script. If you’re going to be using that
technique, the binding() method actually has to be called in the erb.

Sometimes RoR annoys the hell out of me. Why would they deliberately
‘outlaw’ a most basic function?
Because it’s wrong to use it more often than it’s right, maybe?

On 2/24/06, Filip G. [email protected] wrote:

With an echo command I could do this:
code
%>
<%= “whatever you want to write” %>
<%
more code
%>

And that is very tedious.

An echo command is so basic, surely RoR has this?

I also really hate this,
why there is no “echo” in rails

But I did this,

<%=
s = “”

code
s = s + “append something”
code

s
%>


Jual Beli Gratis egold 1$ http://shegold.com/

On Feb 23, 2006, at 9:01 AM, Filip G. wrote:

<%
code
%>
<%= “whatever you want to write” %>
<%
more code
%>

And that is very tedious.

An echo command is so basic, surely RoR has this?

Also instead of concat you can use _erbout if you dont like the
binding part. But I agree with others that its bad fomr to need this
much code in your views. This in not PHP so you dont use echo or
print. But if you must then you can use _erbout like this:

<%
code
_erbout << “Some text”
more code
%>

Cheers-
-Ezra