0
3

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.

link_to の復習

Last updated at Posted at 2020-07-07

#link_toの基本形

<%= link_to "テキスト", "リンク先のパス" %>
<!-- 例 -->
<%= link_to "Yahoo!", "https://www.yahoo.co.jp/" %>

#link_toのmethodオプション

<!-- 例 -->
<%= link_to "削除", "/users/1", method: :delete %>

何も指定しないとGETが指定される。

#link_toのtargetオプション
_blankで新規のウィンドウを開いて表示させる。
_selfで現在のウィンドウで表示させる

<%= link_to 'link_toリファレンス', yokota_path , { :class => "outer", :target => "_blank"} %>

#link_toのclassオプション

<%= link_to "トップページ", "/", class: "hoge" %>

#link_toとhtmlの合わせ技

<%= link_to "/" do %>
  <i class="fas fa-home"></i> トップページ
<% end %>

#画像のリンクを作成しよう

<%= link_to image_tag('test.jpg', class: "クラス名"), 'パス' %>

#dataオプションを使う

<%= link_to "削除", user_path(user), method: :delete, data: { confirm: "本当に削除しますか?" } %>
0
3
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
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?