Matt Elhotiby
Matt Elhotiby

Reputation: 44076

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

Upvotes: 1

Views: 497

Answers (2)

Baldrick
Baldrick

Reputation: 24340

In application.rb

module XXX
  class Application < Rails::Application
    ...

    config.to_prepare do
      Devise::SessionsController.skip_before_filter :check_concurrent_session
    end
  end
end

Upvotes: 1

mogelbrod
mogelbrod

Reputation: 2316

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

Upvotes: 1

Related Questions