Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
67
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

Rails4でSubmitボタンにFontAwesomeのアイコンを埋め込む

色々調べたところ、sanitizeを使う方法や、ブロックで渡す方法などがヒットしましたが、どれもうまくいきませんでした。

最終的にStackOverflowのここを参考にしたところうまくいきました。

Formのsubmit_tagを使うのがそもそも駄目だった様子。
button_tagを使うのがポイントでした。

index.html.erb
<%= f.submit sanitize('<i class="fa fa-search"></i>検索'), :class =>"btn btn-default btn-s-md" %>

button_tagであれば他のどの方法でもOKでした。

index.html.erb
<%= button_tag :type => "submit", :class =>"btn btn-default btn-s-md" do %>
  <i class="fa fa-search"></i>検索
<% end %>


<%= button_tag sanitize('<i class="fa fa-search"></i>検索'), :type => "submit",
    :class =>"btn btn-default btn-s-md" %>


<%= button_tag '<i class="fa fa-search"></i>検索'.html_safe, :type => "submit", 
    :class =>"btn btn-default btn-s-md" %>

参考

bootstrap icon in a submit_tag rails form

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
67
Help us understand the problem. What are the problem?