【问题标题】:Embedded ruby "erb" tags [duplicate]嵌入式红宝石“erb”标签[重复]
【发布时间】:2012-03-01 19:08:41
【问题描述】:

我一直在学习 Ruby 和 Ruby on Rails 的速成课程,但我无法弄清楚: 在嵌入的 ruby​​ html 文件中,有几个标签。 用于执行 用于输出,但是这些标签有什么作用:,末尾的“-”符号是什么?

谢谢。

【问题讨论】:

标签: ruby tags erb


【解决方案1】:

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 过滤而不改变。

【讨论】:

【解决方案2】:

在 ruby​​ 文档中没有关于此用法&lt;%--%&gt; 的详细信息。但这很好用:

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

注意第三个参数'-' ! 相应地使用 &lt;%--%&gt; 时,它会删除前置或后置空白。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-02-03
    • 1970-01-01
    • 1970-01-01
    • 2018-05-17
    • 2015-07-07
    • 1970-01-01
    • 2012-06-05
    • 2011-08-12
    相关资源
    最近更新 更多