LoginSignup
0
0

More than 5 years have passed since last update.

【大枠】button_toはデフォルトでpostでHTTPメソッドを飛ばす

Last updated at Posted at 2016-10-22

button_toはデフォルトでHTTPメソッドがpostになる。

userの編集ボタンを実装している際に、ハマってしまった。
button_toは、きちんとルーティングが指定されていてもデフォルトでHTTPメソッドpostを使用するようになっているため、下記の記述ではエラーが発生する。

= button_to '編集', edit_user_path(shibuya)

編集するためにHTTPメソッドgetを使用したいので指定する記述を書く必要がある。

= button_to '編集', edit_user_path(shibuya), method: :get

method: :getと記述し、HTTPメソッドを指定してあげることでエラーが解決した。
指定しなければbutton_toはHTTPメソッドがpostになると覚えておこう!

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