Search code examples
ruby-on-railssorcery

Rails load from activation token does not load


I try to load a user from an activation token in order to activate him but somehow it fails:

us = User.find(7)
us.activation_token
 => "BqgLeANnMj9jCCsTp2hy" 
@user = User.load_from_activation_token(us.activation_token)
  User Load (0.4ms)  SELECT "users".* FROM "users" WHERE (activation_token = 'BqgLeANnMj9jCCsTp2hy') LIMIT 1
 => nil 

Although user exists and is opening and has an activation token, load_from_activation_token cannot find it. Is there any other possibility to activate a user?


Solution

  • us = User.find(7)
    token = us.activation_token
     => "BqgLeANnMj9jCCsTp2hy" 
    
        @user = User.find_by_activation_token(token)
    
        or 
    
        @user = User.find_by(activation_token: token)
    
        or
    
        @user = User.where(activation_token: token).first