I want to block signup for non-admins so that only a superuser/administrator can add new users. How can I achieve that?
I tried following the method mentioned here: Devise before filter that prevents access to “new_user_registration_path” unless user is signed-in but had no results.
I have installed devise, cancan and rolify. In addition, I also don't want anyone to go to the /users/sign_up
page and sign in. Only admins must have the ability to sign up new users.
Due to the devise installation there is no users controller. Please guide me through making one if needed.
routes.rb
FifthApp::Application.routes.draw do
devise_for :users
resources :qanotes
end
user.rb
class User < ActiveRecord::Base
#resourcify :resources
rolify
has_many :qanotes
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
end
I keep on getting redirected to the root, i.e. localhost:3000, when I try to go to sign up page (only after log in).