0
0

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 3 years have passed since last update.

【Rails】link_toにFontawesomeを適用する方法

Posted at

概要#

link_toを用いた場合にFontawesomeを適用させる方法を説明します。

開発環境#

・データベース:PostgreSQL
・railsのバージョン:6.1.3.2
・Bootstrap:4.5.1
・PC:macbook pro

目標#

下記画像のように編集と削除にFontawesomeを適用させます。

変更前
スクリーンショット 2021-05-27 3.56.49.png

変更後
スクリーンショット 2021-05-27 3.56.15.png

ポイント##

<% link_to 〜 %>の末尾にdoを入れてブロック化することがポイントです。

コード#

変更前
<% @memos.each do |memo| %>
  <p>
    <%= memo.title %>
    <%= memo.body %>
    <%= link_to "削除",memo_path(memo), method: :delete, data: {confirm: "削除しますか?"} %>
    <%= link_to "編集",edit_memo_path(memo) %>
  </p>
<% end %>
変更後
<% @memos.each do |memo| %>
  <p>
    <%= memo.title %>
    <%= memo.body %>
    <%= link_to memo_path(memo), method: :delete, data: {confirm: "削除しますか?"} do %>
      <span class="far fa-trash-alt"></span>
    <% end %>
    <%= link_to edit_memo_path(memo) do%>
      <span class="far fa-edit"></span>
    <% end %>
  </p>
<% end %>
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?