devise icon indicating copy to clipboard operation
devise copied to clipboard

Could not find a valid mapping for #<User

Open ferryphang opened this issue 9 years ago • 3 comments

Hi i facing error here, I have two model called User and Admin and now currently want to add api routes routes.rb

devise_scope :user do
    post 'api/v1/users/forgot_password' => "api/v1/users#forgot_password"
end

but when try to call

@user.send_reset_password_instructions

got this error

RuntimeError (Could not find a valid mapping for

try to debug call Devise.mappings inside that routes it always is

{:admin=>#<Devise::Mapping:0x007fa7444181e0 @scoped_path="admins", @singular=:admin, @class_name="Admin", @klass=#<Devise::Getter:0x007fa7443fbd10 @name="Admin">, @path="admins", @path_prefix=nil, @sign_out_via=:delete, @format=nil, @router_name=nil, @failure_app=Devise::FailureApp, @controllers={:sessions=>"devise/sessions", :passwords=>"devise/passwords"}, @path_names={:registration=>"", :new=>"new", :edit=>"edit", :sign_in=>"sign_in", :sign_out=>"sign_out", :password=>"password"}, @modules=[:database_authenticatable, :rememberable, :recoverable, :validatable, :trackable], @routes=[:session, :password], @used_routes=[:session, :password], @used_helpers=[:session, :password]>}

is it this mappings that show me an error because its not user.. how can i solve this?

ferryphang avatar Jul 05 '17 09:07 ferryphang

Probably you don't have devise_for in your routes? devise_scope won't work if devise_for isn't given. I added

  devise_for :users, only: []

to my routes, to fix this.

pmk1c avatar Aug 22 '17 08:08 pmk1c

@pmk1c is correct. Check if you have the devise_for call. If you do and it still don't work please comment here that we will reopen. Thank you for reporting.

rafaelfranca avatar Aug 22 '17 15:08 rafaelfranca

Hi, I was getting this error when I was running my tests (with chrome headless) and at the same time I was using my app and making changes to the code on development mode.

My solution was setting config.cache_classes = true in config/environments/test.rb to running test with a freezed codebase.

camilova avatar Sep 15 '21 23:09 camilova