In a开发者_StackOverflow社区 standard generated scaffold project, when you are on an edit page, the URL looks like;
/something/3/edit
However, when the page doesn't validate, it runs the following code:
format.html { :action => "edit" }
and the page url changes to;
/something/3
(no /edit)
Why is this is this and how to prevent it, as it looks inconsistent to me and thus confusing.
Thanks
It's because the rendering not change the URL.
When you made an update you made :
PUT /something/3
So if it's failed, there are no URL changing. just rendering of your action file ( not action code ).
So if you want have /new
of /edit
you need made a :
redirect_to :edit
In this case, you lost all information like object.errors
.
Are you sure when fails the code is format.html { :action => "new" }
?
It should be
format.html { :action => "edit" }
I checked it in my own scaffolded code and I get "edit" instead of "new" on that line.
Hope this helps.
精彩评论