gpt4 book ai didi

ruby-on-rails - 添加字段以设计注册 View 后出现“无法重定向到 nil”错误

转载 作者:行者123 更新时间:2023-12-01 23:25:22 24 4
gpt4 key购买 nike

将此行添加到 devise/registrations/new.html.haml 文件后( View ):

  %div
= f.label :account_type
%br/
= f.select(:account_type, [["Usertype1","usertype1"],["Usertype2","usertype2"]], {:selected => nil, :prompt => 'Pick One'})

单击确认电子邮件中的确认链接后,我收到以下错误:

ActionController::ActionControllerError in Devise::ConfirmationsController#show

Cannot redirect to nil!

仅当我在注册时选择 Usertype2 时才会发生。我还使 account_type attr_accessible。 account_type 似乎正在分配(我在 Rails 控制台中检查过)并且开发日志没有任何进一步的信息。

我认为这是发生错误的设计确认 Controller 中的行:

respond_with_navigational(resource){ redirect_to after_confirmation_path_for(resource_name, resource) }

此外,正在确认帐户,但在尝试登录时,我得到以下信息:

undefined method `user_url' for #<Devise::SessionsController:0x9d1659c>

这是在设计 session Controller 的创建操作中。

如有任何帮助,我们将不胜感激。谢谢!

约翰

最佳答案

您提到的两个错误是同一个错误,本质上是当您成功登录时,Devise 无法检测到将您重定向到哪里。当您有多个模型或尝试在路由文件中设置自定义重定向(登录后)时,通常会出现此问题。

尝试在 ApplicationController 中定义路径。

设计文档说 after_sign_in_path_for 方法采用实际模型对象(即:正在登录的模型)

def after_sign_in_path_for(resource)
signed_in_path_for_user
end

注意:您可以对多个 Devise 路径/变量执行相同的操作(覆盖它们)。此外,有关在同一应用程序中对多个 Devise 模型执行此操作的更多信息,您可以查看 this question这是答案。

关于ruby-on-rails - 添加字段以设计注册 View 后出现“无法重定向到 nil”错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8234722/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com