In Rails when a resource create action fails and calls render :new, why must the URL change to the resource's index url?

后端 未结 5 1796
死守一世寂寞
死守一世寂寞 2020-12-07 14:40

I have a resource called Books. It\'s listed as a resource properly in my routes file.

I have a new action, which gives the new view the standard:

@         


        
5条回答
  •  臣服心动
    2020-12-07 15:13

    It doesn't land you at /books/new since you are creating resource by posting to /books/. When your create fails it is just rendering the new action, not redirecting you to the new action. As @MrYoshiji says above you can try redirecting it to the new action, but this is really inefficient as you would be creating another HTTP request and round trip to the server, only to change the url. At that point if it matters you could probably use javascript change it.

提交回复
热议问题