Search code examples
ruby-on-railsrubyruby-on-rails-3authlogic

gem 'authlogic' stack level too deep after upgrade to rails 3.2


I'm getting the following error after upgrading from 'rails', '2.3.15' to 'rails', '3.2.17'

Processing by HomeController#index as HTML
Completed 500 Internal Server Error in 320.9ms

SystemStackError (stack level too deep):
  .bundle/ruby/1.9.1/gems/actionpack-3.2.17/lib/action_dispatch/middleware/reloader.rb:70

I know the error is somewhere in following method:

def current_user
  return @current_user if defined?(@current_user)
  @current_user = current_user_session && current_user_session.record
  Authorization.current_user = @current_user
end

Would be awesome if someone that has implemented authlogic with rails 3 can give me some hints.

Thanks a lot!

Here is my full application controller:

class ApplicationController < ActionController::Base

      helper :all # include all helpers, all the time
      helper_method :current_user_session, :current_user
      helper_method :current_user
      helper_method :current_division

      rescue_from Authorization::AttributeAuthorizationError, :with => :rescue_auth_error

      protect_from_forgery # See ActionController::RequestForgeryProtection for details

      # Scrub sensitive parameters from your log

      around_filter :clear_current_user

      before_filter :require_user
      before_filter :configure_mailers

      private


      def rescue_auth_error(exception)
        if current_user.present?
          UserSession.find(current_user.id).destroy
          flash[:error] = "Your session has expired. Please log in again."
          redirect_to root_url
        end
      end

      def clear_current_user
        remove_instance_variable :@current_user if defined?(@current_user)
        remove_instance_variable :@current_user_session if defined?(@current_user_session)
        yield
        remove_instance_variable :@current_user if defined?(@current_user)
        remove_instance_variable :@current_user_session if defined?(@current_user_session)
        Authorization.current_user = nil
      end

      def current_user_session
        return @current_user_session if defined?(@current_user_session) && !@current_user_session.nil?
        @current_user_session = UserSession.find
        # @current_user_session = current_division.user_sessions.find
      end

      def current_user
        return @current_user if defined?(@current_user)
        @current_user = current_user_session && current_user_session.record
        Authorization.current_user = @current_user
      end

      def require_user
        unless current_user
          store_location
          # flash[:notice] = "You must be logged in to access this page"
          redirect_to new_user_session_url
          return false
        end
      end

      def require_no_user
        if current_user
          store_location
          # flash[:notice] = "You must be logged out to access this page"
          redirect_to account_url
          return false
        end
      end

      def store_location
        session[:return_to] = request.request_uri
      end

      def redirect_back_or_default(default)
        redirect_to(session[:return_to] || default)
        session[:return_to] = nil
      end

      def current_division
        @current_division ||= Division.find_by_code('prd')
      end

      def configure_mailers
        Notifier.configure(request)
      end

      def permission_denied
        flash[:error] = "You do not have permission to access that page."
        redirect_to root_url
      end
    end

Solution

  • This gem was causing the error:

    gem 'rd_searchlogic', :require => 'searchlogic', :git => 'git://github.com/railsdog/searchlogic.git'
    

    Replaced with:

    gem 'ransack'
    

    All is good now.