<%code%>有什么区别?和<%=代码%>在Rails erb中?

编程入门 行业动态 更新时间:2024-10-27 22:27:44
本文介绍了<%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>

更多推荐

&lt;%code%&gt;有什么区别?和&lt;%=代码%&gt;在Rails erb中?

本文发布于:2023-11-04 10:31:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1557689.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有什么区别   代码   code   lt   amp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!