我正在使用devise,并在将表单注册到特定模板后尝试将我的用户重定向。
我已经检查了有关after_inactive_sign_up_path_for
方法的文档,但收到一个异常消息,提示我重定向两次。
RegistrationsController < Devise::RegistrationsController
def create
super
UsersCreateJob.perform_later(resource.id) if resource.persisted?
end
protected
def after_inactive_sign_up_path_for(resource)
render template: 'devise/registrations/success'
end
Exception
AbstractController::DoubleRenderError in RegistrationsController#create
Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at most once per action. Also note that neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like "redirect_to(...) and return".
据我了解,after_inactive_sign_up_path_for
方法会覆盖Devise Registration Controller中的方法并重定向到我的模板,对吗?其他模板来自哪里?
答案 0 :(得分:2)
after_inactive_sign_up_path_for
并不意味着呈现视图。这是将用于重定向的路径。您应该只为动作渲染设置路径'devise/registrations/success'
。
您看到的错误是由于devise控制器调用render / redirect,然后又尝试调用它。