Could not find devise mapping for path “/users/”. How come?

久未见 提交于 2019-12-12 09:55:42

问题


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.


回答1:


Whoops.

I wrote:

devise_scope :users do

Should have been:

devise_scope :user do

user not users.



来源:https://stackoverflow.com/questions/25537327/could-not-find-devise-mapping-for-path-users-how-come

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!