【问题标题】:content_tag not working with f.submit on rails 5.1content_tag 在 Rails 5.1 上无法与 f.submit 一起使用
【发布时间】:2018-09-26 14:05:16
【问题描述】:

我想使用 ruby​​ on rails 表单助手为我的 f.submit 按钮添加引导样式。 但是下面的代码对我不起作用。有谁知道如何使用 rails 5.1 正确执行此操作?

<%= f.submit content_tag(:i, "Add to Cart", class: ["fa", "fa-shopping-cart"]), :class => "primary-btn add-to-cart"%>

我也试过这个,它也不起作用。

<%= f.submit "Add to Cart", :class => "primary-btn add-to-cart"  do %>
       <i class="fa fa-shopping-cart"></i>
    <% end %>

我也尝试过使用 raw 或 HTML_safe。但没有运气。

【问题讨论】:

    标签: ruby-on-rails forms html-safe content-tag


    【解决方案1】:

    提交没有根据documantation 包含标签的选项,因为源中没有块

    你可以试试:

    <%= f.button :class => "primary-btn add-to-cart"  do %>
       <i class="fa fa-shopping-cart">Add to Cart</i>
    <% end %>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-23
      • 1970-01-01
      相关资源
      最近更新 更多