简体   繁体   English

Ruby on Rails上的控制器重定向

[英]Controller redirection on Ruby on Rails

I have a simple question I can't solve : 我有一个简单的问题我无法解决:

In my RoR controller, I have the classical 在我的RoR控制器中,我拥有经典

format.html {redirect_to @document, notice= 'Document was successfully created.'}

But I want to redirect this into a particular page: for example something like 但我想将其重定向到特定页面:例如类似

redirect_to /page/document/:id_document

Do you have the exact syntax to do that ? 你有确切的语法来做到这一点吗? Thank you ! 谢谢 !

Run rake routes in your terminal which will show you path or url helper methods according to your routes something like 在终端中运行rake routes ,它将根据您的路由向您显示路径或url帮助器方法,例如

your_helper GET    /page/document/:id_document     {:action=>"action_name", :controller=>"controller_name"}

then do 然后做

format.html {redirect_to your_helper_path(@document), notice= 'Document was successfully created.'}

OR 要么

You can also use rails polymorphic url like @jvnill suggested 您也可以使用Rails多态网址,例如@jvnill建议

format.html {redirect_to [:page, @document], notice= 'Document was successfully created.'}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM