I'm using Devise for authentication.
I have a custom registration controller in an Api namespace, defined as follow:
class Api::RegistrationsController < Devise::RegistrationsController
# ...
end
My User model is defined outside the Api namespace as follow:
class User < ActiveRecord::Base
# ...
end
In my functional tests, I put the following line in my setup so that Devise knows we work with user and not api_user:
@request.env["devise.mapping"] = Devise.mappings[:user]
It works great in my tests but I don't know how to replicate this behaviour in the real world.
The sign_up_params method looks for params['api_user'] instead of params['user'] when sanitising.
Any idea on how I could do that?
I don't think you still need a solution but I went through the same problem and just solved it :
Instead of
namespace :api do
devise_for :users
end
in your config/routes.rb file, just put :
scope :api, module: :api do
devise_for :users
end
Hope it will help other people :D
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With