I've got a user page, where user can change his settings (users#edit). When user changes his settings and submits. The page is redirected back to users#edit.
I've also got an events page w开发者_运维问答ith a scroll down div (triggered by JS, click event) that lets users edit their settings directly (specifically location).
On the event page. When user edits his settings and submits. It gets redirected to the user settings page (users#edit) instead of back to the events page.
How should I handle this?
I've got two approaches:
- Have a "def update_for_user" in the events controller, which the user form in the events page points to.
- Keep it DRY and pass a params :redirect into the form. Then in the users#update, check if I need to redirect depending on param :redirect?
Any other approach I can take? Your thoughts?
Your code in the update method is probably doing this after a successful edit:
redirect_to :action => 'edit'
But you could change it to this:
redirect_to :back
Which will redirect to the referring page, as passed by the browser in the HTTP_REFERER page, whether it's the event page or the users edit page.
精彩评论