代码之家  ›  专栏  ›  技术社区  ›  Lee McAlilly

在ruby循环的结束标记中添加连字符是什么意思

  •  3
  • Lee McAlilly  · 技术社区  · 15 年前

    我甚至不知道我在这个问题标题中的行话是否准确。

    4 回复  |  直到 15 年前
        1
  •  10
  •   Kasumi    15 年前

        2
  •  2
  •   Patrick Klingemann    15 年前

        3
  •  1
  •   JZ.    15 年前

    在上述代码中不需要连字符。只需添加<%结束%>足以执行嵌入的ruby。

    对连字符的用法作了充分的解释 here

    1   Hyphen at the end of the tag, just the two spaces
    2   before the tag on the line below will be left
    3   <% -%>
    4   Last line
    

    代码将在您的<%-%&燃气轮机;标签

        4
  •  0
  •   mikewilliamson    15 年前

    这意味着它会将\n(或者可能\r\n,我忘记了哪个)添加到行中。 它只影响HTML的格式化方式。

    如果你做了:

    >> helper.image_tag "image.jpg"
    => "<img alt=\"Image\" src=\"/images/image.jpg\" />"
    

    它将输出如下内容:

    "<img alt=\"Image\" src=\"/images/image.jpg\" />\r\n"
    

    这意味着您的html页面看起来像:

    <image tag>
    <whatever other tag>