Reputation: 539
I have implemented the code in Devise call backs in my application controller. First of all is this the right place?
I get both the
after_authentication
and
after_set_user
to work. But I get this error for
before_logout
NoMethodError in Devise::SessionsController#destroy
undefined method `update_attribute' for nil:NilClass
The funny thing is that the database record is updated, dispite the error message. Strange.
Upvotes: 0
Views: 1394
Reputation: 539
This was a while back. When I implemented the after_authentication and before_logout I got multiple records, really strange.
To clarify I wanted to store ip etc on every session not just the last session.
I solved it by adding this in the config/initializers/devise.rb. Add code for what ever you want to store about the session.
Warden::Manager.after_authentication do |user,auth,opts|
#store what ever you want on login
end
Warden::Manager.before_logout do |user,auth,opts|
# store what ever you want on logout
# If not in initializer it will generate two records (strange)
end
Upvotes: 1