0

I have a create action in the controller that I use for a form on the user page as well as in the user index. I want to redirect to the same page the user is on when submitting the form after the form is submitted. This is what I have right now and the form only redirects to @user or '/users'. How can I get it so the user goes back to the page they submitted the form from?

def create
 @user = User.find(params[:relationship][:followed_id])
 current_user.follow!(@user)
 redirect_to @user or '/users'
end
1
  • If you have new method, you can try redirect_to new Commented Mar 27, 2012 at 4:11

1 Answer 1

2

Use

redirect_to :back

This will redirect the user back to the page that they submitted the form.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.