#17 ✓resolved
Josh Owens

Authlogic::Session::Base.controller error

Reported by Josh Owens | December 11th, 2008 @ 06:11 PM


I am having an issue with the gem in a rails 2.2.2 generated project. I see this in my tests and in my development log files:

You must activate the Authlogic::Session::Base.controller with a controller object before creating objects

I tried switching the environment.rb file to 2.1.2, and I still see the same error in my tests, but the authlogic plugin seems to be working better.


Comments and changes to this ticket

  • Ben Johnson

    Ben Johnson December 11th, 2008 @ 06:24 PM

    • State changed from “new” to “open”

    Are you having this issue only for tests?

  • Ben Johnson

    Ben Johnson December 11th, 2008 @ 07:14 PM

    • State changed from “open” to “resolved”

    If this is happening in just tests you should checkout the "testing" section in the readme. If you are trying to test the model directly you need to activate it with a controller object. That is like a database connection to ActiveRecord.

    Authlogic::Session::Base.controller = Authlogic::ControllerAdapters::RailsAdapter.new(my_controller_object)

    In my apps, I test the controllers that use Authlogic, since Authlogic is not really a model, its more of a controller utility.

  • Josh Owens

    Josh Owens December 11th, 2008 @ 07:21 PM

    I see it when using rspec tests, but not only there. I also see it when running 2.2.2 (Every time) or when I hit a named route that I made, first.


    ActionController::Routing::Routes.draw do |map| map.resources :users map.resource :user_session

    map.resources :pages

    map.signup 'signup', :controller => "users", :action => "new" map.login 'login', :controller => "user_sessions", :action => "new"

    map.root :page end

    When I hit /user_session/new or /login, it throws that same error. As far as the tests go, I am testing the UserSessionController, not the faux-model.

  • Josh Owens

    Josh Owens December 11th, 2008 @ 07:22 PM


    ActionController::Routing::Routes.draw do |map| map.resources :users map.resource :user_session

    map.resources :pages

    map.signup 'signup', :controller => "users", :action => "new" map.login 'login', :controller => "user_sessions", :action => "new"

    map.root :page end

  • Ben Johnson

    Ben Johnson December 11th, 2008 @ 07:42 PM

    I currently have Authlogic in 3 different projects using Rails 2.2.2. I don't think it is rails. Do you have any special plugins or doing anything special with before_filters. Here is all that authlogic does to activate itself:

    before_filter :activate_authlogic
    def activate_authlogic
      Authlogic::Session::Base.controller = Authlogic::ControllerAdapters::RailsAdapter.new(self)

    For some reason that filter is not being added. I have a feeling something tricky is going on with your before filters. Just to test, try adding this in your application controller:

    before_filter :activate_authlogic

    Authlogic mixes in that method for you, so it should be available.

  • Josh Owens

    Josh Owens December 11th, 2008 @ 08:05 PM

    It must have something to do with one of my plugins... When I add the line you mention (the before filter) everything starts working like it should.

    Here is a list of my gems:

    authlogic * factory_girl * will_paginate * rspec-rails

    plugins: * delayed_job * friendly_id * haml * subdomain_fu * thinking_sphinx

  • Ben Johnson

    Ben Johnson December 11th, 2008 @ 08:07 PM

    If I had to guess, it would be subdomain_fu or maybe friendly_id (not sure what that is). But those are the only ones that mess around with the controller. My guess is that they did not properly mix in their methods or add their before_filters.

  • Josh Owens

    Josh Owens December 11th, 2008 @ 08:26 PM

    It is the rspec-rails gem. I went through all the stuff I listed.

  • misexadury

    misexadury August 30th, 2018 @ 09:28 AM

    In this area of the projects, you can buy the tickets with the special offers. Get the overview about all the scene created here. You can also go to the link of assignmenthelponline.co.uk and can make the special arrangements for your deal.

  • lijyfuhe

    lijyfuhe September 16th, 2018 @ 04:11 AM

    Not only you but also everyone else in the league has problem with gem but that is also a rule and your right to have positive critic on others as the competitors and other professionals do with Osteo Sydney so that they are not used as the first line treatment in broken and dislocated parts of the body.

  • Samuel596

    Samuel596 December 21st, 2018 @ 06:47 AM

    Basically Ahoy disables all before filters, which means that Authlogic isn't initialised before Ahoy, so it raises the exception you see. To fix this, I used the branch in the PR above that allows specified filters to be run, and then added the code below to my ahoy.rb initialiser file prepaidgiftbalance.

  • lindarose11

    lindarose11 December 24th, 2018 @ 04:29 AM

    The article you have shared here very awesome. I really like and appreciated your work. I read deeply your article, the points you have mentioned in this article are useful
    Sushi Cat 2

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Object based authentication solution that handles all of the non sense for you. It's as easy as ActiveRecord is with a database.

People watching this ticket