我想阻止註冊非管理員,以便只有超級用戶/管理員才能添加新用戶。我怎樣才能做到這一點?Rails 4設計,如何登錄新用戶?
我試着按照這裏提到的方法:Devise before filter that prevents access to 「new_user_registration_path」 unless user is signed-in但沒有結果。
我已經安裝了devise,cancan和rolify。另外,我也不希望任何人訪問/users/sign_up
頁面並登錄。只有管理員必須有能力註冊新用戶。
由於設計安裝沒有用戶控制器。如果需要,請指導我做一個。
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
我一直被重定向到根,即本地主機:3000,當我嘗試去註冊頁面(只有在登錄後)。