Created
December 4, 2018 13:42
-
-
Save inneroot/daca1d0122d06b92037b8ceb76c2c6e7 to your computer and use it in GitHub Desktop.
Device gem with one user allowed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/controllers/registrations_controller.rb | |
class RegistrationsController < Devise::RegistrationsController | |
before_action :one_user_registered?, only: [:new, :create] | |
protected | |
def one_user_registered? | |
if User.count == 1 | |
if user_signed_in? | |
redirect_to root_path, alert: 'Регистрация новых пользователей отключена' | |
else | |
redirect_to new_user_session_path, alert: 'Регистрация новых пользователей отключена' | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment