如果用户在以下控制器中使用之前的过滤器未经身份验证...
before_action :authenticate_user!
...默认情况下,Devise会将用户发送到login(new_session)页面。
如何将它们发送到注册页面(new_registration)呢?
我是否需要覆盖应用程序中的某些方法或设计控制器?
答案 0 :(得分:0)
在Routes.rb
devise_scope :user do
authenticated :user do
root '(something)', as: :authenticated_root
end
unauthenticated do
root 'new_user_registration#new', as: :unauthenticated_root
end
end
答案 1 :(得分:0)
部分代码正常运行,但未经身份验证的用户无法访问主页。不是我想要的。这是解决方案
并将一段代码更改为..
def redirect_url
new_user_registration_url
end
答案 2 :(得分:0)
使用route方法定义自定义失败应用,该方法将返回表示命名路由的符号以重定向到:
# app/lib/my_failure_app.rb
class MyFailureApp < Devise::FailureApp
def route(scope)
:new_user_registration_url
end
end
然后在Devise初始化程序中,指定失败的应用程序:
# config/initializers/devise.rb
config.warden do |manager|
manager.failure_app = MyFailureApp
end
如果遇到未初始化的常量CustomFailure错误,并且已将CustomFailure类放在/ lib目录下,请确保将lib文件自动加载到application.rb文件中,如下所示
config.autoload_paths << Rails.root.join('lib')