繁体   English   中英

Ruby on Rails上的控制器重定向

[英]Controller redirection on Ruby on Rails

我有一个简单的问题我无法解决:

在我的RoR控制器中,我拥有经典

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

但我想将其重定向到特定页面:例如类似

redirect_to /page/document/:id_document

你有确切的语法来做到这一点吗? 谢谢 !

在终端中运行rake routes ,它将根据您的路由向您显示路径或url帮助器方法,例如

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

然后做

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

要么

您也可以使用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