From 411b565ccacf592db08cfb9bee83296166166baf Mon Sep 17 00:00:00 2001 From: Rodrigo Rosenfeld Rosas Date: Wed, 18 Apr 2012 15:29:13 -0300 Subject: [PATCH] Better handling of previously enabled Devise model deserialization --- lib/devise/rails/warden_compat.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/devise/rails/warden_compat.rb b/lib/devise/rails/warden_compat.rb index 237be849..d1861b3d 100644 --- a/lib/devise/rails/warden_compat.rb +++ b/lib/devise/rails/warden_compat.rb @@ -21,17 +21,23 @@ class Warden::SessionSerializer end def deserialize(keys) - klass, *args = keys + klass_name, *args = keys begin - ActiveSupport::Inflector.constantize(klass).serialize_from_session(*args) + klass = ActiveSupport::Inflector.constantize(klass_name) + if klass.respond_to? :serialize_from_session + klass.serialize_from_session(*args) + else + Rails.logger.warn "[Devise] Stored serialized class #{klass_name} seems not to be Devise enabled anymore. Did you do that on purpose?" + nil + end rescue NameError => e if e.message =~ /uninitialized constant/ - Rails.logger.debug "[Devise] Trying to deserialize invalid class #{klass}" + Rails.logger.debug "[Devise] Trying to deserialize invalid class #{klass_name}" nil else raise end end end -end \ No newline at end of file +end