当前位置:网站首页>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.new
On 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 :newend
This 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
/books
Rather than instead of
/books/new
Which 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_path
But 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边栏推荐
- [user defined type] structure, union, enumeration
- dynamic programming
- The printf function is realized through the serial port, and the serial port data reception is realized by interrupt
- Dell筆記本周期性閃屏故障
- 随时随地查看远程试验数据与记录——IPEhub2与IPEmotion APP
- New feature of Oracle 19C: automatic DML redirection of ADG, enhanced read-write separation -- ADG_ REDIRECT_ DML
- Configuring OSPF basic functions for Huawei devices
- Learn to use code to generate beautiful interface documents!!!
- String comparison in batch file - string comparison in batch file
- Threejs image deformation enlarge full screen animation JS special effect
猜你喜欢
How to judge whether an element in an array contains all attribute values of an object
Telerik UI 2022 R2 SP1 Retail-Not Crack
Mujoco finite state machine and trajectory tracking
筑梦数字时代,城链科技战略峰会西安站顺利落幕
Chapter II proxy and cookies of urllib Library
Installation and testing of pyflink
Five different code similarity detection and the development trend of code similarity detection
重上吹麻滩——段芝堂创始人翟立冬游记
Hero League | King | cross the line of fire BGM AI score competition sharing
alexnet实验偶遇:loss nan, train acc 0.100, test acc 0.100情况
随机推荐
JS+SVG爱心扩散动画js特效
Chenglian premium products has completed the first step to enter the international capital market by taking shares in halber international
Telerik UI 2022 R2 SP1 Retail-Not Crack
迈动互联中标北京人寿保险,助推客户提升品牌价值
C9 colleges and universities, doctoral students make a statement of nature!
Advanced learning of MySQL -- basics -- transactions
第五篇,STM32系统定时器和通用定时器编程
5种不同的代码相似性检测,以及代码相似性检测的发展趋势
What kind of experience is it to realize real-time collaboration in jupyter
The printf function is realized through the serial port, and the serial port data reception is realized by interrupt
STM32开发资料链接分享
Lombok makes ⽤ @data and @builder's pit at the same time. Are you hit?
Advanced learning of MySQL -- basics -- multi table query -- self join
Js+svg love diffusion animation JS special effects
paddlehub应用出现paddle包报错的问题
A brief history of deep learning (I)
Chapter II proxy and cookies of urllib Library
学习光线跟踪一样的自3D表征Ego3RT
Slam d'attention: un slam visuel monoculaire appris de l'attention humaine
Stm32f407 ------- SPI communication