设计:无法关闭require_no_authentication?

当我尝试限制注册访问时,似乎不可能。 我试过了

class RegistrationsController < Devise::RegistrationsController skip_before_filter :require_no_authentication end 

在app / registrations_controller.rb中并​​将路由更改为

 devise_for :accounts, :controllers => { :registrations => "registrations" } 

这不起作用。 任何建议为什么以及我能做什么/我应该在哪里看,将不胜感激。

编辑:

不起作用意味着:当我在注销时尝试访问/ accounts / sign_up时,它确实有效,但我应该重定向到sign_in。

解决方法:

 class RegistrationsController < Devise::RegistrationsController skip_before_filter :require_no_authentication private def authenticate_account!(opts={}) opts[:scope] = :account warden.authenticate!(opts) # if !devise_controller? || opts.delete(:force) end end 

这将删除跳过对每个Devise控制器的身份validation的硬编码检查。 代码来自lib/devise/controllers/helpers.rb

因此,您希望在注销路径后进行更改 。

如果您还没有设置root来设计登录

 class ApplicationController < ActionController::Base private # Overwriting the sign_out redirect path method def after_sign_out_path_for(resource_or_scope) new_user_session_path end end