如何将超赞的字体图标嵌入Submit_tag [英] How to embed font-awesome icons into submit_tag

查看:136
本文介绍了如何将超赞的字体图标嵌入Submit_tag的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试为我的按钮使用字体很棒的图标,但是我无法使其显示在submit_tag中

Trying to user font awesome icons for my buttons but I cant get it to show in the submit_tag

 <%= submit_tag icon("search"), class: "btn-primary", style:"width:40px;" %>

输出:

 <input class="btn-primary" name="commit" style="width:40px;" type="submit" value="&lt;i class='icon-search' style='font-size:1em' &gt;&lt;/i&gt;">

助手:

def icon(name, size=1)
  #icon("camera-retro")
  #<i class="icon-camera-retro"></i> 

  html = "<i class='icon-#{name}' "
  html += "style='font-size:#{size}em' "
  html += "></i>"
  html.html_safe
end

当我删除助手的html.html_safe行时,我得到的是相同的东西.就像html_safe无法正常工作.我也尝试了html = raw(html)也不起作用.

when I remove the html.html_safe line of the helper I get the same thing. its like html_safe is not working. I have also tried html = raw(html) with no effect either.

推荐答案

输入提交标签不允许嵌套HTML,您需要显示HTML.

Input submit tags don't allow nested HTML, which you need to show an icon.

尝试使用按钮代替

<button class='btn btn-primary' style='width:40px;'>
  <%= icon("search") %>
</button>

值得注意的是,按钮标签和输入提交标签的行为之间存在一些差异.请查看此SO问题,以获得大量详细信息.我个人没有在应用程序中使用按钮标签的问题.但是,YMMV是针对不同的浏览器等的.

It's worth noting some differences between the behaviour of button tags and input submit tags. Check out this SO question for a bunch of great details. I personally haven't had issues using button tags in my applications. YMMV with respect to different browsers and such, though.

这篇关于如何将超赞的字体图标嵌入Submit_tag的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆