"echo function" for ROR

hello

I’m looking for something similar to the “echo” PHP function for ruby.
in some situation I don’t like to write code like this:

<% if condition %>
<%= “

this is an example

” %>
<% end %>

I prefer write this:

<%
if condition
echo “

this is an example


end
%>

I’m looking for something similar to the “echo” PHP function for ruby.
in some situation I don’t like to write code like this:
I’m not sure you can. Have a look at:
http://api.rubyonrails.org/classes/ActionView/Base.html

This isn’t really a huge problem though as most logic should be kept out
of the templates. You can also use inline conditions for cleaner code:

<%= “My Stuff” if my_condition %>

This method can be used to render parts of the page based on controller
determined logic:

<%= render(:partial => “user/dashboard”) if @show_dashboard %>

Hope that helps,

Steve

Gonzalo wrote the following on 09.09.2006 13:14 :

<%
if condition
echo “

this is an example


end
%>

<% if condition %>

this is an example


<% end %>

Does the same… You only have to use <%= %> for dynamic content.

But you can use concat IIRC:

<%
if condition
concat “

this is an example


end
%>

Then you can replace the static HTML above by dynamic content.

Lionel.

<%= if true: “Hi!” end %>

Or, even shorter:

<%= “Hi!” if true %>

thanks a lot, Stephen and Lionel.

both solutions was very usefuls

Aren’t colons going the way of the dinosaur?

<%= if true; “Hi!” end %>

There.