I am using a devise scope for my password reset route, and it is hitting the controller but not the actual method inside the controller. Mind boggling... Any help is appreciated.
devise_scope :dashboard_users do
post 'forgot_password', to: 'sessions#forgot_password'
put 'reset_password', to: 'sessions#reset_password'
end
That's in my routes.rb and then this is my sessions_controller
class Api::Dashboard::V1::SessionsController < Devise::SessionsController
p "hello"
def forgot_password
...
end
end
It will print the "hello" but wont print or execute any code inside the method.
hello
Processing by Api::Dashboard::V1::SessionsController#forgot_password as */*
Parameters: {"email"=>"[email protected]"}
[Devise] Could not find devise mapping for path "/api/dashboard/v1/forgot_password".
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]
I don't know the exact answer to your question, but I have some ideas. First, the p "hello"
is getting executed on file load, not on the request. It's probably confusing because Rails will automatically reload your controller on requests, printing the "hello" message. You can test this in an IRB console:
class Test
p "hello"
end
Second, I would take a look at your rake routes
output. You may be sending requests to the wrong place. My hunch is that you need to adjust your to
settings for the routes to something like:
post 'forgot_password', to: 'api/dashboard/v1/sessions#forgot_password'
put 'reset_password', to: 'api/dashboard/v1/sessions#reset_password'
That change will point the requests to your properly namespaced controller. The previous routes may have sent requests to a different sessions controller that was defined on the global namespace by either you or Devise.