1

I have a Rails 4 route as below. This defaults to a GET route. How do I make it a PUT? I'm using this route for in-place form editing but the edits don't save in the database. I'm not sure if making this a PUT is the solution but wanted to try it out. Is there a way to get the same route be a GET and PUT?

get 'orderupdate' => "orders#update"
Moosa
  • 3,126
  • 5
  • 25
  • 45

2 Answers2

1

Yes, just change the method from get to put:

put 'orderupdate' => "orders#update"

Also, be sure to use your HTTP verbs correctly.

Community
  • 1
  • 1
August
  • 12,410
  • 3
  • 35
  • 51
0

You should uses put/patch verb for updating so you can change your route to use both of them by

match 'orderupdate', to: "orders#update", via: [:put, :patch]

Instead of using individual routes like this, i'll recommend you to use rails resourceful routes by:

resources :orders

which will automatically create crud routes for you

Mandeep
  • 9,093
  • 2
  • 26
  • 36