公告
财富商城
积分规则
提问
发文
2019-02-12 02:04发布
甜甜的少女心
There seems to be a difference between the two, Though I can't tell what exactly.
<% code %>
And
<%= code %>
<% %> will evaluate the ruby code contained
<% %>
<%= %> will evaluate and render the code contained
<%= %>
So a template containing:
Hello <% user.name %> how are you?
...would output:
Hello how are you
...whilst...
Hello <%= user.name %> how are you?
Hello fred how are you
<% %> is commonly used for iterators
<ul> <% @users.each do |user| %> <li><%= user.name %></li> <% end %> </ul>
The <% and %> only evaluates the ruby code between them, while <%= and %> outputs the result of evaluation. Don't mix up though
<%
%>
<%=
This will output "foo" to the access log and nil to the browser output
nil
<%= puts "foo" %>
while
<%= "foo" %>
will output "foo" string to the browser.
<%= %> prints the return value of code statement into the browser and <% %> just executes the code.
最多设置5个标签!
<% %>
will evaluate the ruby code contained<%= %>
will evaluate and render the code containedSo a template containing:
...would output:
...whilst...
...would output:
<% %>
is commonly used for iteratorsThe
<%
and%>
only evaluates the ruby code between them, while<%=
and%>
outputs the result of evaluation. Don't mix up thoughThis will output "foo" to the access log and
nil
to the browser outputwhile
will output "foo" string to the browser.
<%= %>
prints the return value of code statement into the browser and<% %>
just executes the code.