21
15

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.

Railsでlink_toの中にHTMLを入れ子で入れる

Posted at

Railsのテンプレートの「link_to」でHTMLのタグを入れたい場合。

以下のような記述だとエラーになります。

<%= link_to "<i class="MyClass"></i><em>リンク</em>", :session, method: :delete %>

「文字列.html_safe」という方式が使えないので、HTMLの入れ子で入れる場合には以下のようにします。

<%= link_to :session, method: :delete do %>
<i class="MyClass"></i><em>リンク</em>
<% end %>

尚、HTMLの表示では以下のようになります。

<a rel="nofollow" data-method="delete" href="/session">
<i class="MyClass"></i><em>リンク</em>
</a>
21
15
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
21
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?