【问题标题】:Rails strips html class tag from button_toRails 从 button_to 中剥离 html 类标签
【发布时间】:2014-01-17 23:54:22
【问题描述】:

我的观点如下:

      <%= button_to 'Check In', controller: "posts", action: :check_in, id: @post.id, :class => "btn", :style => "display:inline" %>

由于某种原因,:class 和 :style 不会出现在呈现的 HTML 中。我尝试将此类和样式放在其他 ERB 标记上,然后从那里渲染它们。为什么他们只在这个标签上被剥离?

【问题讨论】:

    标签: ruby-on-rails erb


    【解决方案1】:

    button_to(name = nil, options = nil, html_options = nil, &amp;block)

    所以,您需要将 options 和 html_options 属性包装到哈希中

    &lt;%= button_to 'Check In', { controller: "posts", action: :check_in, id: @post.id }, { :class =&gt; "btn", :style =&gt; "display:inline" } %&gt;

    【讨论】:

      【解决方案2】:

      许多标签助手要求 HTML 属性位于 :html 键中。

      <%= button_to 'Check In', controller: "posts", action: :check_in, id: @post.id, :html => {:class => "btn", :style => "display:inline"} %>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-07-21
        • 2013-07-11
        • 1970-01-01
        • 2014-10-09
        • 1970-01-01
        • 1970-01-01
        • 2010-10-24
        • 2012-11-21
        相关资源
        最近更新 更多