“<%="之间的差异和“<%"将 ruby 与 html 混合时? [英] Difference between "<%=" and "<%" when mixing ruby with html?
本文介绍了“<%="之间的差异和“<%"将 ruby 与 html 混合时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在学习 Rails,我正在做一个练习,我必须在视图文件中混合一些 html 和 ruby.
I'm learning Rails, and i'm doing a exercise which i have to mix some html with ruby in a view file.
在编码 ruby 时,"<%= #code %> "和"<% #code %> "之间的主要区别是什么?
What is the main difference between " <%= #code %> " and " <% #code %> ", when coding ruby?
推荐答案
<%= something which you would like to have displayed in your view %>
<% something you would like to have hidden,
(or something which doesn't display anything in the view) such as a
conditional statement %>
<% if @post.nil? %>
<%= render "nilNotify" %>
<% else %>
<%= @post.content %>
<% end %>
这篇关于“<%="之间的差异和“<%"将 ruby 与 html 混合时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文