I have a /account
page that routes to users#edit
and the form action is /users/1
. When there are errors, the rendered page is /users/1
. How can make the errors render at /account
again?
If I redirect I lose those errors I need to display.
I suppose if it's a GET then do users#edit
if it's a PUT then do users#update
. Is that the right way? How should I write my routes?
You could make a route for POST /account
that calls users#update
:
# config/routes.rb
get '/account' => 'users#edit'
post '/account' => 'users#update'
Your form can now POST
to /account and if there are validations errors the rendered view will have a URL of /account.
However this is breaking the RESTful pattern and patterns should only be broken if there's a good reason to break them.