我通过在继承的 registrations_controller 中定义 after_sign_up_path_for(resource) 来调用它:
class RegistrationsController < Devise::RegistrationsController
protected
def after_sign_up_path_for(resource)
new_user_profile_path(resource)
end
end
如果我不自定义路由,此重定向工作正常。但是,当我这样做时,它不再起作用。我的路线文件有:
devise_for :users, skip: [:sessions], controllers: { registrations: "registrations" }
devise_scope :user do
get 'signin' => 'devise/sessions#new', as: :new_user_session
post 'signin' => 'devise/sessions#create', as: :user_session
delete 'signout' => 'devise/sessions#destroy', as: :destroy_user_session
get 'signup' => 'devise/registrations#new', as: :new_user_registration
post 'signup' => 'devise/registrations#create', as: :user_registration
root to: 'pages#home'
end
具体来说,post 'signup' => 'devise/registrations#create', as: :user_registration 行把事情搞砸了。如果那不存在,它工作正常。但是,如果不存在,那么当由于验证错误导致注册失败时,URL 默认为 /users 而不是 /signup,这是不受欢迎的行为。
任何人都知道这是我做错了什么还是设计中有错误?