i found this "executed with no substitution back into the output" , but maybe my English wasn't too good , i cant really understand what it means. Can anyone help out?
+5
A:
Sometimes you will have to (or you want to) execute some ruby statements but not for output purpose.
like the following:
<% if @user.nil? %>
Hi, welcome!
<% else %>
Hi, <%= @user.name %>!
<% end %>
Of course this is just one use case, but sometimes you do need <% %>
:D
PeterWong
2010-10-17 07:34:55
+1
A:
Code in <% %>
(without equal) is executed "with no substitution back into the output" means you want to execute code WITHOUT any output, like a loop and the best part is, it can be used with a non ruby code.
<% 3.times do %>
<h1>Hello world</h1>
<%end%>
This will give:
<h1>Hello world</h1>
<h1>Hello world</h1>
<h1>Hello world</h1>
zengr
2010-10-17 07:35:57
ohh , thanks. So with = there must have to be an output!
wizztjh
2010-10-17 07:59:55
+1
A:
<% %>
Will execute Ruby code with no effect on the html page being rendered. The output will be thrown away.
<%= %>
Will execute Ruby code and insert the output of that code in place of the <%= %>
example...
<% puts "almost" %> nothing to see here
would render as
nothing to see here
however
<%= puts "almost" %> nothing to see here
would render as
almost nothing to see here
Michelle Six
2010-10-17 07:37:32