找不到路径“/ users /”的设计映射。怎么来的? [英] Could not find devise mapping for path "/users/". How come?

查看:244
本文介绍了找不到路径“/ users /”的设计映射。怎么来的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在和devise / omniauth一起工作。通过facebook / twitter注册后,我想重定向到一个名为验证电子邮件的页面,他们可以验证他们的电子邮件地址是否正确。



我只是试图让 localhost:3000 / users / verify-email 页面正常工作。我去那个网址,我收到这个错误信息:


找不到路径/ users / update_email的设计映射。这可能是由于两个原因:1)您忘记将路由包裹在作用域中。例如:devise_scope:user do get/ some / route=>some_devise_controllerend 2)您正在测试绕过路由器的Devise控制器。如果是这样,您可以明确告诉Devise要使用的映射:@ 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',
注册:'custom_devise_controllers / registrations'}

devise_scope:users do
getusers / verify_email=> 'custom_devise_controllers / registrationENTS#verify_email'
end
...
end

我不认为我的路由不正确地包含在范围块中(这是错误消息中#1的内容)。这是否意味着我需要明确告诉Devise哪个映射要使用(哪个是错误消息的第2个)?错误消息说我可以告诉devise使用哪个映射: @ 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

如果success_updated
set_flash_message:通知,更新

sign_in @user,:bypass => true
redirect_to after_update_path_for(@user)
else
呈现编辑
结束
结束

def after_sign_up_path_for(资源)
users_update_email_path
end

def verify_email
end

private
def needs_password?(user,params)
params [:用户] [:密码] .present? || PARAMS [:用户] [:password_confirmation] .present?
end
end

谢谢!如果你们想知道有关我的代码的更多信息,只需让我知道。

解决方案

糟糕。 b
$ b

我写道:

  devise_scope:users do 

应该是:

  devise_scope:用户do 

用户不是用户。


I am working with devise/omniauth right now. After signing up through facebook/twitter, I want to redirect to a page called "verify-email" where they can verify that their email address is correct.

I am just trying to get the localhost:3000/users/verify-email page to work right now. I go to that url and I get this error message:

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].

So here is my 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

I don't think I wrap the route in the scope block incorrectly (which is what #1 of the error message talks about). Does that mean I need to explicitly tell Devise which mapping to use (which is what #2 of the error message is about)? The error message says I can tell devise which mapping to use with this: @request.env["devise.mapping"] = Devise.mappings[:user]. Should I put that in my custom_devise_controllers/registrations_controller.rb? Or do you guys think something else is going on?

I will include my "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

Thanks! If you guys want to know any more info about my code, just let me know.

解决方案

Whoops.

I wrote:

devise_scope :users do

Should have been:

devise_scope :user do

user not users.

这篇关于找不到路径“/ users /”的设计映射。怎么来的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆