rubycas / rubycas-client

Ruby client for Yale's Central Authentication Service protocol -- an open source enterprise single sign on system for web applications.
http://code.google.com/p/rubycas-client/
Other
332 stars 217 forks source link

undefined method `destroy' for {}:Hash #4

Closed millisami closed 12 years ago

millisami commented 14 years ago

This was all fine till Rails3.0.0.4.beta Today I upgraded the rails to rc and now its blowing up while logging out.

NoMethodError in SessionsController#logout

undefined method `destroy' for {}:Hash

app/controllers/sessions_controller.rb:16:in `logout'

sessions_controller.rb

class SessionsController < ApplicationController

  before_filter CASClient::Frameworks::Rails::GatewayFilter, :only => :index
  before_filter CASClient::Frameworks::Rails::Filter, :except => :index

  def index
    redirect_to root_url
  end

  def login_complete
    redirect_to root_url
  end

  def logout
    reset_session
    CASClient::Frameworks::Rails::Filter.logout(self, root_url) and return
  end
end
sampoo commented 13 years ago

I had the same problem on Rails 2.3.9

Below is a snippet from the source of lib/casclient/frameworks/rails/filter.rb

As you can see, the reset_session is already called in this method.

In your case, you're calling it twice, once in your logout method and once in the logout method of CASClient. Thereby, the second call tries to destroy an empty Hash object, resulting in a NoMethodError.

The fix is to simply comment out the reset_session in your own method.

      def logout(controller, service = nil)
        referer = service || controller.request.referer
        st = controller.session[:cas_last_valid_ticket]
        delete_service_session_lookup(st) if st
        controller.send(:reset_session)
        controller.send(:redirect_to, client.logout_url(referer))
      end