Search code examples
ruby-on-railsrubyruby-on-rails-3devisebefore-filter

Is there a way to overwrite the devise sessions controller create action?


I want to know if there is a way to overwrite the devise sessions controller create action within the application controller. So i have this code

  def check_concurrent_session
    if is_already_logged_in?
      flash[:error] = "We're sorry, you can't login to two places concurrently."
      sign_out_and_redirect(current_user)
    end
  end

and I need this to run everywhere on the site other then create action in the devise sessions controller..

So i have a before_filter on the application controller, but can i exclude a contoller like

before_filter :check_concurrent_session, :except => ["somecontoller"]

obviously this is wrong but you get the idea. I know i can create my own sessions controller and inherit from devise but i want to know if this is possible to do this from within application controller


Solution

  • before_filter :check_concurrent_session
    
    def check_concurrent_session
      return if controller_name == 'some_controller'
      if is_already_logged_in?
        flash[:error] = "We're sorry, you can't login to two places concurrently."
        sign_out_and_redirect(current_user)
      end
    end