问题描述
我尝试使用以下代码创建 registration_controller.rb :
class RegistrationsController < Devise::RegistrationsController
protected
def after_sign_up_path_for(resource)
"/projects"
end
def after_sign_in_path_for(resource)
raise
"/projects"
end
end
甚至没有让我参加提高
作为一种解决方法,我设法使其在 application_controller.rb 中创建一个方法,如下所示:
def after_sign_in_path_for(resource)
"/projects"
end
但是我想知道为什么我没有覆盖默认的RegistrationsController类。
解决方法
根据Devise文档,您可以通过运行rails generate devise:controllers [scope]
自定义其配置,例如,将范围替换为users
。
然后它生成如下文件:
class Users::RegistrationsController < Devise::RegistrationsController
# GET /resource/sign_in
# def new
# super
# end
...
end
您可以取消注释所需的方法,并在super
之后编写代码。