Using font awesome with formtastic submit button

若如初见. 提交于 2019-12-07 07:04:53

问题


I have a submit button on my form:

= semantic_form_for record do |form|
  = form.actions do
    = form.submit 'Save'

I want to add an icon from FontAwesome, with link_to I can use a block:

= link_to record do
  = fa_icon 'save'
  Save

But this doesn't work with Formtastic's form.submit.

I also tried:

= form.submit fa_icon('save')
= form.submit fa_icon('save').html_safe

But both renders escaped HTML.

How do I add a font-awesome icon to the <button> tag?


回答1:


Try using capture to set a label, as in:

- label = capture do
  = fa_icon 'save'
  Save
= form.button label

This only seems to work for form.button, but not for form.submit. You'll have to use form.button label, type: :submit.



来源:https://stackoverflow.com/questions/24460266/using-font-awesome-with-formtastic-submit-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!