My Devise/Warden-based app stores a model ID in the session[] variable. I want destroy the object when the session[] is destroyed.
- Is there a callback or some mechanism to notify my app when the session is destroyed?
- Is the mechanism dependable, or should I run a nightly cleanup script to vacuum up any orphaned objects?
To make it clear, here’s a snippet of my controller code:
class WizardsController < ApplicationController
before_filter :find_or_create_wizard
...
private
def find_or_create_wizard
@wizard = Wizard.find_by_id(session[:wizard_id]) || Wizard.create.tap {|w| session[:wizard_id] = w }
end
end
To restate the question: how and when should I destroy the Wizard object?
Use the Warden::Hooks https://github.com/hassox/warden/blob/master/lib/warden/hooks.rb to do things after sign out or authentication.