<%code%>有什么区别?和<%=代码%>在Rails erb中? [英] What's the difference between <% code %> and <%= code %> in Rails erb?
本文介绍了<%code%>有什么区别?和<%=代码%>在Rails erb中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尽管我无法确切说明这两者之间,两者之间似乎有所不同。
There seems to be a difference between the two, Though I can't tell what exactly.
<% code %>
和
<%= code %>
推荐答案
<%%> ;
将评估其中包含的红宝石代码
<% %>
will evaluate the ruby code contained
<%=%>
计算并渲染其中包含的代码
<%= %>
will evaluate and render the code contained
因此模板包含:
Hello <% user.name %> how are you?
...将输出:
Hello how are you
...怎么样...
...whilst...
Hello <%= user.name %> how are you?
...将输出:
Hello fred how are you
< ;%%>
通常用于迭代器
<ul>
<% @users.each do |user| %>
<li><%= user.name %></li>
<% end %>
</ul>
这篇关于<%code%>有什么区别?和<%=代码%>在Rails erb中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文