代码之家  ›  专栏  ›  技术社区  ›  Obromios

使用concat content\u标记获取双线分隔符[duplicate]

  •  0
  • Obromios  · 技术社区  · 7 年前

    我的助手的工作方式如下:

    def some_help(in_string)
      in_string + " and more"
    end
    

    但我想把它变成一个

    所以

    def some_help(in_string)
      "<br/>" + in_string + " and more"
    end
    

    0 回复  |  直到 13 年前
        1
  •  40
  •   Ashitaka    10 年前

    使用 tag(:br) 而不是 "<br/>" .

    content_tag(:br) 创建打开和关闭 br 标签和使用 raw html_safe

        2
  •  2
  •   heavysixer    13 年前

    您也可以使用“content\u tag”视图助手。

    http://api.rubyonrails.org/classes/ActionView/Helpers/TagHelper.html#method-i-content_tag

    def some_help
       content_tag(:br) + "some help"
    end
    
        3
  •  1
  •   ksol    13 年前

    我不太明白你的意思。你加上 <br /> 在你的字符串中,当你想让它有换行符的效果时,它保持原样?如果是这样的话,你必须把你的字符串标记为html安全的。你这样做是因为 "somestring".html_safe .

        4
  •  0
  •   Matzi    13 年前

    .html_safe 在绳子上。