LoginSignup
26
30

More than 5 years have passed since last update.

Rails link_to にHTMLタグを含む文字列を挿入する

Posted at

最近は、CSSのスタイル等が複雑で、link_to で生成される文字の部分にHTMLタグを挿入したい場合がある。
この場合は、どうやら link_to のブロック構文というものも存在するようだ。

index.html.erb
<%= link_to index_index_path do %>
    <i class="icon-home"></i>Home</a>
<% end %>   

これによって、下記のHTMLタグが生成される。

index.html
<a href="/index/index">
    <i class="icon-home"></i>Home
</a>

これは便利。
今後はブロック構文というものも勉強しよう。

26
30
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
26
30