Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Provide model callbacks for confirm! method #812

morgoth opened this Issue Jan 27, 2011 · 5 comments


None yet
3 participants

morgoth commented Jan 27, 2011

We would like to define model callbacks (before_confirm, etc.), however this is impossible with method with bang.
Also confirm! is simply calling save without bang and without validations, so it looks like there is no need for exclamation mark for this method.
After this change we would like to introduce these callbacks (before_confirm, after_confirm) in devise using define_model_callbacks method from ActiveModel::Callbacks.

I can prepare a patch with confirm! method deprecation if you think it can be merged into master.


josevalim commented Jan 27, 2011

Hey, thanks for taking the time to suggest improvements to Devise.

Every time we have a need to change the confirmation behavior, we simply overwrite the confirm! method and call super. Isn't that something you can do? So far I am avoiding adding callbacks, because it would quickly become a callback super (before_confirm, after_reset_password, after_unlock and so on). What do you think?

morgoth commented Jan 27, 2011

I agree, that having callbacks for all possible methods would be a pain.
However it would be nice to have some official public API for developers. Currently we can always hack and overwrite devise methods, but there is a problem that something can be broken in future releases, so we must maintain our code with devise changes more carefully.


josevalim commented Jan 27, 2011

confirm! is definitely an official public method. Overriding a method and calling super is not a hack, but a Ruby feature that can be well used once you have an established API.

benoror commented May 6, 2011

Just to double-check. By overwriting confirm! this way would send the welcome email ONLY after the user have confirmed its account?

class User < ActiveRecord::Base
def confirm!



josevalim commented May 6, 2011

Use the mailing list for questions please? Anyway, I think the answer is yes. Try looking at Devise controllers source code and see when confirm! is called.

This issue was closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment