66
63

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Posted at

色々調べたところ、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

66
63
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
66
63

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?