Skip to content
This repository

Fixed SinatraAdapter problem in rails2 branch #326

Merged
merged 3 commits into from over 1 year ago

2 participants

Caio Torres Ben Johnson
Caio Torres

Fixed a problem that was ocurring when using a Sinatra application coupled via Rack, like resque-web, and authlogic in rails2 branch on the same application. The exception raised was:

authlogic/lib/authlogic/controller_adapters/sinatra_adapter.rb:50:in included': undefined methodbefore' for Sinatra::Request:Class (NoMethodError)

Also I accidentally pushed to this branch another fix that I made. I added a session_class_namespace option, so that it is possible to define the namespace of the session class, making it easy for authlogic to find it. I can remove this if you want so.

Ben Johnson yourewelcome merged commit f975f52 into from October 23, 2012
Ben Johnson yourewelcome closed this October 23, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
17  lib/authlogic/acts_as_authentic/session_maintenance.rb
@@ -48,12 +48,25 @@ def session_ids(value = nil)
48 48
         end
49 49
         alias_method :session_ids=, :session_ids
50 50
         
  51
+        # In some cases, you can use a different namespace for the session class. If you want to use a model
  52
+        # to control access in a namespace and edit it in another namespace, you can define the session class
  53
+        # namespace here so authlogic knows where to find it without problems.
  54
+        #
  55
+        # * <tt>Default:</tt> nil
  56
+        # * <tt>Accepts:</tt> Strings
  57
+        def session_class_namespace(value = nil)
  58
+          rw_config(:session_class_namespace, value, nil)
  59
+        end
  60
+        alias_method :session_class_namespace=, :session_class_namespace
  61
+        
51 62
         # The name of the associated session class. This is inferred by the name of the model.
52 63
         #
53 64
         # * <tt>Default:</tt> "#{klass.name}Session".constantize
54 65
         # * <tt>Accepts:</tt> Class
55 66
         def session_class(value = nil)
56  
-          const = "#{base_class.name}Session".constantize rescue nil
  67
+          namespace = rw_config(:session_class_namespace, nil)
  68
+
  69
+          const = ((namespace.nil? ? "" : "#{namespace}::") + "#{base_class.name}Session").constantize rescue nil
57 70
           rw_config(:session_class, value, const)
58 71
         end
59 72
         alias_method :session_class=, :session_class
@@ -136,4 +149,4 @@ def session_class
136 149
       end
137 150
     end
138 151
   end
139  
-end
  152
+end
2  lib/authlogic/controller_adapters/sinatra_adapter.rb
@@ -58,4 +58,4 @@ def self.included(klass)
58 58
   end
59 59
 end
60 60
 
61  
-Sinatra::Request.send(:include, Authlogic::ControllerAdapters::SinatraAdapter::Adapter::Implementation)
  61
+Sinatra::Base.send(:include, Authlogic::ControllerAdapters::SinatraAdapter::Adapter::Implementation)
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.