Skip to content

Commit

Permalink
* Added check to make sure Authlogic is not loaded too late, causing …
Browse files Browse the repository at this point in the history
…a NotActivated error.
  • Loading branch information
binarylogic committed Jul 4, 2009
1 parent 90626be commit 694d75f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.rdoc
@@ -1,4 +1,4 @@
== 2.1.1 released 2009-6-27
== 2.1.1

* Use mb_chars when downcasing the login string to support international characters.
* Check for the existence of the :remember_me key before setting remember_me off of a hash.
Expand Down
12 changes: 11 additions & 1 deletion lib/authlogic/controller_adapters/rails_adapter.rb
Expand Up @@ -3,6 +3,8 @@ module ControllerAdapters
# Adapts authlogic to work with rails. The point is to close the gap between what authlogic expects and what the rails controller object
# provides. Similar to how ActiveRecord has an adapter for MySQL, PostgreSQL, SQLite, etc.
class RailsAdapter < AbstractAdapter
class AuthlogicLoadedTooLateError < StandardError; end

def authenticate_with_http_basic(&block)
controller.authenticate_with_http_basic(&block)
end
Expand All @@ -23,9 +25,17 @@ def request_content_type
# Lets Authlogic know about the controller object via a before filter, AKA "activates" authlogic.
module RailsImplementation
def self.included(klass) # :nodoc:
if defined?(::ApplicationController)
raise AuthlogicLoadedTooLateError.new("Authlogic is trying to prepend a before_filter in ActionController::Base to active itself" +
", the problem is that ApplicationController has already been loaded meaning the before_filter won't get copied into your" +
" application. Generally this is due to another gem or plugin requiring your ApplicationController prematurely, such as" +
" the resource_controller plugin. The solution is to require Authlogic before these other gems / plugins. Please require" +
" authlogic first to get rid of this error.")
end

klass.prepend_before_filter :activate_authlogic
end

private
def activate_authlogic
Authlogic::Session::Base.controller = RailsAdapter.new(self)
Expand Down

0 comments on commit 694d75f

Please sign in to comment.