gpt4 book ai didi

ruby-on-rails - 找不到路径 "/users/"的设计映射。怎么会?

转载 作者:数据小太阳 更新时间:2023-10-29 08:15:47 27 4
gpt4 key购买 nike

我现在正在使用 devise/omniauth。通过 facebook/twitter 注册后,我想重定向到一个名为“验证电子邮件”的页面,他们可以在其中验证他们的电子邮件地址是否正确。

我只是想让 localhost:3000/users/verify-email 页面立即工作。我转到该 url 并收到此错误消息:

Could not find devise mapping for path "/users/update_email". This may happen for two reasons: 1) You forgot to wrap your route inside the scope block. For example: devise_scope :user do get "/some/route" => "some_devise_controller" end 2) You are testing a Devise controller bypassing the router. If so, you can explicitly tell Devise which mapping to use: @request.env["devise.mapping"] = Devise.mappings[:user].

这是我的 routes.rb:

Rails.application.routes.draw do
...
devise_for :users, :controllers => {
omniauth_callbacks: 'custom_devise_controllers/omniauth_callbacks',
registrations: 'custom_devise_controllers/registrations' }

devise_scope :users do
get "users/verify_email" => 'custom_devise_controllers/registrations#verify_email'
end
...
end

我认为我没有错误地将路由包装在范围 block 中(这是错误消息的#1 所讨论的内容)。这是否意味着我需要明确告诉 Devise 要使用哪个映射(错误消息的第 2 条是关于什么的)?错误消息说我可以告诉设计使用哪个映射:@request.env["devise.mapping"] = Devise.mappings[:user]. 我应该把它放在我的 custom_devise_controllers/registrations_controller.rb?还是你们认为发生了其他事情?

我将包含我的“custom_devise_controllers/registrations_controller.rb”:

class CustomDeviseControllers::RegistrationsController < Devise::RegistrationsController
def update
@user = User.find(current_user.id)

successfully_updated = if needs_password?(@user, params)
@user.update_with_password(devise_parameter_sanitizer.sanitize(:account_update))
else

params[:user].delete(:current_password)
@user.update_without_password(devise_parameter_sanitizer.sanitize(:account_update))
end

if successfully_updated
set_flash_message :notice, :updated

sign_in @user, :bypass => true
redirect_to after_update_path_for(@user)
else
render "edit"
end
end

def after_sign_up_path_for(resource)
users_update_email_path
end

def verify_email
end

private
def needs_password?(user, params)
params[:user][:password].present? || params[:user][:password_confirmation].present?
end
end

谢谢!如果你们想知道关于我的代码的更多信息,请告诉我。

最佳答案

糟糕。

我写道:

devise_scope :users do

应该是:

devise_scope :user do

用户不是用户。

关于ruby-on-rails - 找不到路径 "/users/"的设计映射。怎么会?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25537327/

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