【问题标题】:'Render and/or redirect were called multiple times in this action' on devise“在此操作中多次调用渲染和/或重定向”在设计上
【发布时间】:2019-09-02 21:54:26
【问题描述】:

我正在使用设计并尝试在注册表单后将我的用户重定向到特定模板。

我已经检查了有关 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 方法会覆盖来自设计注册控制器的方法并重定向到我的模板,对吗?这个其他模板来自哪里?

【问题讨论】:

    标签: ruby-on-rails ruby devise


    【解决方案1】:

    after_inactive_sign_up_path_for 并不是要渲染视图。这是将用于重定向的路径。您应该只放置一个动作渲染的路径'devise/registrations/success'

    您看到的错误是由于设计控制器调用了渲染/重定向,然后您也尝试调用它。

    【讨论】:

    • 感谢您的回答@mrzasa,但这对我来说有点困惑。我正在创建一个名为 success 的方法,也是它的路由,并使 after_inactive_sign_up_path_for 重定向到具有“设计/注册/成功”的“success_path”,但得到相同的错误。我理解错了吗? :(
    • 你不应该在after_inactive_sign_up_path_for中重定向,只需返回方法的路径:def after_inactive_sign_up_path_for; success_path; end
    • 如果我这样做,我的资源为零,这意味着它没有通过我的 create 方法。创建后,我想重定向到一个特定的视图,说明他/她注册成功(但他/她需要确认电子邮件)。
    猜你喜欢
    • 1970-01-01
    • 2019-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多