如何禁用设计中的操作,rails
How to disable an action in devise, rails
我正在使用 Rails 和 Devise。 devise 创建了一个 Admin
模型。
我怎样才能禁止创建管理员? (如何禁用 create
和 new
操作是设计控制器)
我的Rails版本是6.0.1
禁用new
和create
意味着禁用Sign up
,这是由Devise的registerable
模块提供的。在 admin
模型中,从以下列表中删除 :registerable
devise :database_authenticatable, :registerable, ...
它将禁用 devise 提供的 registration
功能。
您可以使用带有 devise_for
的 skip:
选项来跳过任何 Devise 控制器的路由生成:
devise_for :admins, skip: :registrations
如果您仍然想让管理员更新和销毁他们的帐户,您需要手动重新添加这些路由:
devise_for :admins, skip: :registrations
devise_scope :admin do
resource :admin_registration, only: [:edit, :update, :destroy],
path: 'admins',
controller: 'devise/registrations'
end
我正在使用 Rails 和 Devise。 devise 创建了一个 Admin
模型。
我怎样才能禁止创建管理员? (如何禁用 create
和 new
操作是设计控制器)
我的Rails版本是6.0.1
禁用new
和create
意味着禁用Sign up
,这是由Devise的registerable
模块提供的。在 admin
模型中,从以下列表中删除 :registerable
devise :database_authenticatable, :registerable, ...
它将禁用 devise 提供的 registration
功能。
您可以使用带有 devise_for
的 skip:
选项来跳过任何 Devise 控制器的路由生成:
devise_for :admins, skip: :registrations
如果您仍然想让管理员更新和销毁他们的帐户,您需要手动重新添加这些路由:
devise_for :admins, skip: :registrations
devise_scope :admin do
resource :admin_registration, only: [:edit, :update, :destroy],
path: 'admins',
controller: 'devise/registrations'
end