【问题标题】:How to put a glyphicon in a simple_form submit in Rails?如何在 Rails 中将 glyphicon 放入 simple_form 提交中?
【发布时间】:2014-06-24 04:32:14
【问题描述】:

我想编辑我的 simple_form 提交按钮,将标签替换为字形图标,但无法做到。

有没有很好的方法来执行这个技巧?

非常感谢!

编辑:

带有工作按钮的Haml代码:

= link_to [:admin, comment], method: :delete, data:{confirm: "are you sure ?"}, class: "btn btn-sm btn-danger" do
  %i.glyphicon.glyphicon-trash

但它不适用于提交按钮...

【问题讨论】:

  • sublime_form - 你确定吗?
  • 没有文件,至少添加你的html
  • 修正了错字,我的错。例如也添加了 HAML 工作代码。

标签: ruby-on-rails haml simple-form glyphicons


【解决方案1】:

这样做的好方法是简单地输入 button 而不是简单的 submit 输入,因为 from 中的按钮会提交它。

= f.button :submit do
  %i.glyphicon.glyphicon-user
  Add user

它确实有效。

好像simple_form对表单提交的代码结构比较严格。

【讨论】:

    【解决方案2】:

    对于 rails 4.2+ 和 'simple_form (~> 3.1.0) 对我有用的是改变

    <%= f.button :submit, class: 'btn btn-success' %>
    

    <%= f.button :button, class: 'btn btn-success' do %>
            <span class="glyphicon glyphicon-ok" aria-hidden="true></span> Update Form
        <% end %>
    

    通过改变

    1. :提交到:按钮
    2. 在介绍字形图标时添加跨度
    3. 添加文本标签,它是自动生成的,但现在如果我想要任何文本,我需要提供它

    【讨论】:

    • 谢谢。为我工作!
    猜你喜欢
    • 2014-01-19
    • 1970-01-01
    • 1970-01-01
    • 2015-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-27
    • 1970-01-01
    相关资源
    最近更新 更多