Redirect To Next Action in Rails
Here’s a simple way of redirecting to a different page depending on the previous page in Rails.
Lets say you want to redirect to a different action depending on where the user publishes an article.
In your view, set the
:next_action parameter in the
In the controller you can check whether the
:next_action parameter exists, or fall back to a default.
fetch method will take the value of
params[:next_action] if it exists, otherwise will fall back to the second argument.
You can carry the parameter through multiple actions (e.g.
cart --> log in --> checkout) through hidden fields in forms
or in the submit action of a form.