Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom devise resource name

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?

like image 526
Antoine Avatar asked May 18 '26 07:05

Antoine


1 Answers

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

like image 71
Uelb Avatar answered May 20 '26 20:05

Uelb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!