Refine confirm_at column no longer updated after rails 3.2 + devise 2.0

After switching to rails 3.2 and development 2.0 and clicking on the confirmation link sent by e-mail or copied from the console during the development process, the confirm_at column is not updated. Therefore, you cannot log in.

What will be the approach to fix this, since nothing appears in the logs, the available attributes have confirm_at, so the column must be updatable.

+4
source share
2 answers

Multiple axles for troubleshooting.

First (obvious :-)), which you activated for confirmation in the user model

devise : :confirmable 

Then check that the following columns are defined in your database and in your model (similarly if you are on Mongoid with a different type)

 ## Confirmable t.string :confirmation_token t.datetime :confirmed_at t.datetime :confirmation_sent_at # t.string :unconfirmed_email # Only if using reconfirmable 

And finally (I don’t know that this applies to you and makes the problem), but confirmation was confirmed in 2.0

In addition, several configuration parameters have been renamed or deleted:

Devise.confirm_within has been renamed Devise.allow_unconfirmed_access_for;

What then gives you the rails console for the new user just built?

Gotta give something like

 User.last => #<User .... email: " youremail@example.com ", confirmation_token: "abch76UfqHBBxHw97123", confirmed_at: nil, confirmation_sent_at: 2012-02-10 11:06:41 UTC, unconfirmed_email: nil, ....> 

And the link you received (which you can also manually copy in the browser manually, should look like (and match the confirmation token above)

 <p><a href="http://localhost:5000/users/confirmation?confirmation_token=abch76UfqHBBxHw97123">Confirm my account</a></p> 

The user in the console must be changed accordingly.

 User.last => #<User .... email: " youremail@example.com ", confirmation_token:nil, confirmed_at: confirmed_at: 2012-02-10 11:28:04 UTC, confirmation_sent_at: 2012-02-10 11:06:41 UTC, unconfirmed_email: nil, ....> 

If while copying the link the browser still doesn’t work, can you copy the last lines of the logs?

around

 20:36:51 web.1 | Started GET "/users/confirmation?confirmation_token=abch76UfqHBBxHw97123" for 127.0.0.1 at 2012-02-10 20:36:51 +0900 20:36:51 web.1 | [127.0.0.1] Processing by Devise::ConfirmationsController#show as HTML 20:36:51 web.1 | [127.0.0.1] Parameters: {"confirmation_token"=>"abch76UfqHBBxHw97123"} 
+8
source

(I translated it into a clear answer, because he deserves it, I think)

{"confirm_token" => "PAPe74HyVmRheFbaBAaw"} User load (0.4ms) SELECT users. * FROM users WHERE users.confirmation_token = 'PAPe74HyVmRheFbaBAaw' LIMIT 1 (0.2ms) BEGIN (0.1ms) COMMIT Completed 401 Unauthorized at 15ms

Do you use with CanCan? This is a configuration problem in Cancan! If you uninstall CanCan this will probably work :-). However, in this case, the CanCan Wiki has an elegant solution.

Put the following in your ApplicationController:

 check_authorization :unless => :devise_controller? 

https://github.com/ryanb/cancan/wiki/Ensure-Authorization

Conditionally check authorization

As with CanCan 1.6, the check_authorization method supports: if and: except options. Any of them accepts a method name as a symbol. This method will be called to determine if an authorization check will be performed. Is it very easy to skip this check on all Devise controllers as they provide a devise_controller? Method.

 class ApplicationController < ActionController::Base check_authorization :unless => :devise_controller? end 
+1
source

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


All Articles