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

destroyアクションのmethod指定方法

Last updated at Posted at 2018-11-10

aタグとlink_toメソッドのどちらでもmethodを指定できるようになりたい

メモアプリを作成していて、投稿したメモの削除機能を作っています。「削除」ボタンをaタグとlink_toメソッドを用いた場合では指定方法が異なるので、両方の指定方法を記録しておきます。(ルーティングはどちらも同じ)

aタグの場合

show.html.erb
<a href="/memos/<%=memo.id%>" data-method="delete">削除</a>

link_toメソッドの場合

show.html.erb
<%= link_to "削除", "/memos/#{memo.id}", :method => :delete %>
0
0
1

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?