【问题标题】:Converting HTML to content_tag in Ruby on Rails在 Ruby on Rails 中将 HTML 转换为 content_tag
【发布时间】:2010-12-27 01:18:54
【问题描述】:

如何将此 HTML 转换为 Rails content_tag 辅助语法/格式?

<p class="msg">
    <span class="strong">Most people enjoy the inferiority of their best friends.</span>
    <br>
    <span class="emphasize"> - Lord Chesterfield</span>
</p>

【问题讨论】:

    标签: html ruby-on-rails ruby


    【解决方案1】:

    准确地说是添加了类。如果你有一堆行,你也可以使用带有 content_tags 的块。

    content_tag(:p, :class => 'msg') do
      content_tag(:span, "Most ... friends.", :class => "strong") +
      content_tag(:br) + 
      content_tag(:span, "- Lord .. ", :class => "emphasize")
    end
    

    【讨论】:

    【解决方案2】:

    这就是你要找的吗?

    content_tag(:p, content_tag(:span,  'Most people enjoy the inferiority of their best friends.') + '<br/>' + content_tag(:span, ' - Lord Chesterfield'))
    

    【讨论】:

      猜你喜欢
      • 2016-10-02
      • 2021-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-23
      • 1970-01-01
      • 2017-05-05
      • 2014-06-04
      相关资源
      最近更新 更多