简体   繁体   中英

Controller redirection on Ruby on Rails

I have a simple question I can't solve :

In my RoR controller, I have the classical

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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