Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails Devise - How to redirect to a Getting Started Link - After validating an email

I'm using Devise with my rails 3 app. The app requires users to validate their email before continuing.

How can I redirect users to a specific url like /gettingstarted after they successfully validate their email address via the email confirmation msg they receive?

Thanks

like image 766
AnApprentice Avatar asked Jan 21 '23 21:01

AnApprentice


1 Answers

When a user clicks on the confirm link they are taken to a confirm page which checks the confirmation token and if it's valid automatically logs them into the application. You could overwrite the after_sign_in_path_for method in your ApplicationController (as shown on the Devise wiki) and then redirect them to your getting started page the first time a user logs in.

def after_sign_in_path_for(resource_or_scope)
  if resource_or_scope.is_a?(User) && first login
    getting_started_path
  else
    super
  end
end

For "first login" you could test if the confirmed_at timestamp is within a couple minutes of now, if your also using the trackable module in devise you can check if the sign_in_count is 1 or you could create your own field in the user model that tracks this information.

like image 54
Braden Becker Avatar answered Jan 29 '23 10:01

Braden Becker