当前位置:网站首页>In rails, when the resource creation operation fails and render: new is called, why must the URL be changed to the index URL of the resource?
In rails, when the resource creation operation fails and render: new is called, why must the URL be changed to the index URL of the resource?
2022-07-07 00:59:00 【fyin1314】
problem :
I have a resource called Books. I have a resource called books .It's listed as a resource properly in my routes file. It is correctly listed as a resource in my routing file .
I have a new action, which gives the new view the standard: I have a new action , It provides a standard for new views :
@book = Book.newOn the model, there are some attributes which are validated by presence, so if a save action fails, errors will be generated. On the model , Some properties are verified by existence , So if the save operation fails , An error is generated .
In my controller: In my controller :
@book = Book.create... # some logicif @book.save redirect_to(@book)else render :newendThis is pretty standard; This is very standard ;and the rationale for using render:new is so that the object is passed back to the view and errors can be reported, form entries re-filled, etc. Use render:new The basic principle of is to pass objects back to the view and report errors 、 Refill form entries, etc .
This works, except every time I'm sent back to the form (via render :new), my errors show up, but my URL is the INDEX URL, which is It works , Except every time I am sent back to the form ( By rendering :new) when , My mistakes will show up , But mine URL yes INDEX URL, It is
/booksRather than instead of
/books/newWhich is where I started out in the first place. This is where I started .I have seen several others posts about this problem, but no answers. I have read several other posts on this issue , But there is no answer .At a minimum, one would assume it would land you at /books/create, which I also have a view file for (identical to new in this case). At least , People will assume that it will let you enter /books/create, I also have a view file ( In this case with new identical ).
I can do this: I can do this :
# if the book isn't saved thenflash[:error] = "Errors!"redirect_to new_book_pathBut then the @book data is lost, along with the error messages, which is the entire point of having the form and the actions, etc. But then @book Data and error messages are lost , This is the whole meaning of having forms and operations .
Why is render :new landing me at /books, my index action, when normally that URL calls the INDEX method, which lists all the books? Why? render :new Log me in to /books, My indexing operation , Usually it's time to URL call INDEX Method , This method lists all books ?
Solution :
Reference resources : https://stackoom.com/en/question/ynXG边栏推荐
- Leetcode (547) - number of provinces
- 接口(接口相关含义,区别抽象类,接口回调)
- 再聊聊我常用的15个数据源网站
- 第六篇,STM32脉冲宽度调制(PWM)编程
- Attention SLAM:一种从人类注意中学习的视觉单目SLAM
- paddlehub应用出现paddle包报错的问题
- Linear algebra of deep learning
- How do novices get started and learn PostgreSQL?
- Mujoco produces analog video
- Web project com mysql. cj. jdbc. Driver and com mysql. jdbc. Driver differences
猜你喜欢

随时随地查看远程试验数据与记录——IPEhub2与IPEmotion APP

ActiveReportsJS 3.1中文版|||ActiveReportsJS 3.1英文版

【YoloV5 6.0|6.1 部署 TensorRT到torchserve】环境搭建|模型转换|engine模型部署(详细的packet文件编写方法)

第五篇,STM32系统定时器和通用定时器编程

stm32F407-------DAC数模转换

Memory optimization of Amazon memorydb for redis and Amazon elasticache for redis

Mujoco Jacobi - inverse motion - sensor

Lombok 同时使⽤ @Data 和 @Builder 的坑,你中招没?

Installation and testing of pyflink
![[yolov5 6.0 | 6.1 deploy tensorrt to torch serve] environment construction | model transformation | engine model deployment (detailed packet file writing method)](/img/1a/2b497a1baa04d84d28da715d097dfe.png)
[yolov5 6.0 | 6.1 deploy tensorrt to torch serve] environment construction | model transformation | engine model deployment (detailed packet file writing method)
随机推荐
Stm32f407 ------- SPI communication
Hero League | King | cross the line of fire BGM AI score competition sharing
stm32F407-------SPI通信
Leetcode (547) - number of provinces
第六篇,STM32脉冲宽度调制(PWM)编程
【JVM调优实战100例】04——方法区调优实战(上)
Tencent cloud webshell experience
Advanced learning of MySQL -- basics -- multi table query -- subquery
C9 colleges and universities, doctoral students make a statement of nature!
dynamic programming
【软件逆向-求解flag】内存获取、逆变换操作、线性变换、约束求解
Lombok makes ⽤ @data and @builder's pit at the same time. Are you hit?
深入探索编译插桩技术(四、ASM 探秘)
AI super clear repair resurfaces the light in Huang Jiaju's eyes, Lecun boss's "deep learning" course survival report, beautiful paintings only need one line of code, AI's latest paper | showmeai info
pyflink的安装和测试
How to get started and improve test development?
Policy Gradient Methods
Model-Free Prediction
Lombok 同时使⽤ @Data 和 @Builder 的坑,你中招没?
Model-Free Control