嵌入式ruby“erb”标签

时间:2012-02-09 10:00:54

标签: ruby tags erb

我一直在经历Ruby和Ruby on Rails的速成课程,我无法弄清楚这一点: 在嵌入式ruby html文件中,有几个标签。 < %%>执行 <%=%>输出,但这些标签服务的功能是什么:<%= - %>,最后带有“ - ”符号的是什么?

感谢。

2 个答案:

答案 0 :(得分:2)

This link包含对erb标记的良好概述。

来自网站:

  
    

认可的标签

  
     

ERB识别提供的模板中的某些标签并转换为   他们基于以下规则:

<% Ruby code -- inline with output %>

<%= Ruby expression -- replace with result %>

<%# comment -- ignored -- useful in testing %>

% a line of Ruby code -- treated as <% line %> (optional -- see ERB.new)

%% replaced with % if first thing on a line and % processing is used

<%% or %%> -- replace with <% or %> respectively
     

所有其他文本都通过ERB过滤传递不变。

答案 1 :(得分:1)

在ruby文档中,没有关于此用法的详细信息<%--%>。但它的效果很好:

erbA = ERB.new(erbA_str, 1, '-', "@output_buffer")

注意第3个参数'-' ! 在相应地使用<%--%>时,它会删除前置或后置空格。

相关问题