开发者

RoR: How to prevent Url change after erronous edit?

开发者 https://www.devze.com 2022-12-31 07:02 出处:网络
In a开发者_StackOverflow社区 standard generated scaffold project, when you are on an edit page, the URL looks like;

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消