What I was going for was to redirect to the previous page the user was on after the user logs in, by doing "request.referer" . However, when the user chooses submit, they get redirected to the login page, but request.referer was being set to the page before "submit". Thus I used session[:submit] to tell whether the user was coming from the submit page or not.