Rails Devise - How to redirect to the Getting Started link - after checking your email

I am using Devise with my rail 3 application. To continue, the application must confirm your email.

How can I redirect users to a specific URL, such as / getstarted, after they successfully verify their email address through the confirmation email that they receive?

thanks

+4
source share
4 answers

When the user clicks on the confirmation link, they go to the confirmation page, which checks the confirmation token, and if it is valid, automatically registers them in the application. You can overwrite the after_sign_in_path_for method in your ApplicationController ( as shown in the Devise quiz ), and then redirect them to your home page when you first log on to the system.

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 the “first login” you can check if the mark with the confirmed_ is in a couple of minutes, if you also use the developed tracking module, you can check if sign_in_count 1 is equal, or you can create your own field A user who tracks this information.

+9
source

I check the source code at https://github.com/plataformatec/devise/blob/master/app/controllers/devise/confirmations_controller.rb

and it seems that we have a callback to do this "after_confirmation_path_for", but I could not get it to work without rewriting. Devise :: ConfirmationController

I hope this helps, and if anyone earns by simply defining after_confirmation_path_for, just let us know.

0
source

I am using the last_sign_in_at field from the tracking model to achieve this. I have the following code in my root action:

 if current_user.last_sign_in_at.nil? then redirect_to :controller => :users, :action => :welcome end 

http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Trackable

It seems to work quite well.

0
source

inside 'after_sign_in_path_for' current_user.last_sign_in_at.nil? will not work, because after the first login, this happens. However this will work

 if current_user.sign_in_count == 1 # do 1 thing else # do another thing end 
0
source

Source: https://habr.com/ru/post/1332288/


All Articles