What are some simple ways to hook into Devise so that I can distinguish between the following events: 1. sign up, 2. sign in
I just need to know how to hook in to Devise for this. I haven’t found what I’m looking for yet — a clean, minimal, controller-level implementation. Here are some options that I’ve tried:
-
Create a custom controller (as mentioned at https://github.com/plataformatec/devise#configuring-controllers). I’d rather not use this because it is a lot of work, brittle, and duplicative.
-
Use model callbacks. I’d rather not go down this path. I want this to be controller-level code. By that I mean that, at least, I want access to the controller environment. In my mind, this is a controller responsibility. I want this to be testable without having to deal with models.
-
Override
sign_inin my app’s ApplicationController. The problem? This approach can not distinguish between a sign up and a sign in. (Please correct me if this is not accurate?) I say this after skimming the Devise registrations_controller.rb and sessions_controller.rb — both of theircreatemethods callsign_in.
My specific applications are: (a) sending email notices to admins and (b) making API calls to back-end analytic services. Note that neither are model responsibilities — these are controller-level (application-level) responsibilities.
Update 2012-10-16: I’m asking if the Devise project would be open to adding a new hook for sign_up: https://github.com/plataformatec/devise/issues/2104
Update 2012-10-16: I removed “sign out” from this question because that is easy to hook into.
Thanks to a pull request from https://github.com/pootsbook and https://github.com/rubynortheast, the master branch of Devise now supports separate hooks for sign_up and sign_out. So I think will make it into the next release, perhaps 2.1.3.
See: