Skip to content

Instantly share code, notes, and snippets.

@inneroot
Created December 4, 2018 13:42
Show Gist options
  • Save inneroot/daca1d0122d06b92037b8ceb76c2c6e7 to your computer and use it in GitHub Desktop.
Save inneroot/daca1d0122d06b92037b8ceb76c2c6e7 to your computer and use it in GitHub Desktop.
Device gem with one user allowed
# 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