Skip to content

Instantly share code, notes, and snippets.

@tiegz
Created August 2, 2011 19:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiegz/1121054 to your computer and use it in GitHub Desktop.
Save tiegz/1121054 to your computer and use it in GitHub Desktop.
Prioritize order of Authlogic::Session::Base persistence callbacks for Rails 2
class UserSession < Authlogic::Session::Base
... # rest of your code
private
# Reorder persist_callback_chain at runtime (only way I know of doing this).
def run_callbacks(kind, options = {}, &block)
self.class.send("#{kind}_callback_chain").tap { |callback_chain|
if kind.to_s == "persist"
# Define the type of persistence methods
# This example "params" being first means that "persist_by_params" would fire first
[:params, :session, :http_auth, :cookie].reverse.each do |auth_method|
if index = callback_chain.map(&:method).index("persist_by_#{auth_method}".to_sym)
callback_chain.unshift(callback_chain.delete_at(index))
end
end
end
}.run(self, options, &block)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment