I have a link in all sent emails that leads users to a page that allows them to edit their email settings. However, if the user is not logged in when he or she clicks on the link, an error is thrown (since the email settings are pulled through the association with current_user).
I’d like to instead show the login page if the user is not currently signed in, and upon signing in, they are redirected to the email settings page. What is a good way of setting up this logic? I’m using Ruby on Rails and Devise for authentication.
Assuming the edit action in email_settings controller is called, add the
authenticate_user!helper from devise as a before filter.Devise will take care of redirecting the user to the login page and on successful login, take the user back to the email settings page.