devise: Devise validation fails with can't be blank even if I send values properly
I have posted this issue that I have on SO as well, I am not sure if this is an issue with Devise, probably this is not, but still I can’t understand what am I doing wrong.
basically, I am sending values using Postman, post request with proper headers and params, but I can’t get passed this can’t be blank validation error.
If this is not an issue with Devise, I guess you can just close it. Thank you.
Started POST "/api/users" for 127.0.0.1 at 2015-07-01 17:05:26 +0300
Processing by Api::Users::RegistrationsController#create as JSON
Parameters: {"user"=>{"email"=>"usermail@gmail.com", "password"=>"[FILTERED]", "first_name"=>"firstName", "last_name"=>"lastName"}}
(0.1ms) BEGIN
(0.1ms) ROLLBACK
Completed 200 OK in 17ms (Views: 0.2ms | ActiveRecord: 3.8ms)
{"user":{"email":["can't be blank"],"password":["can't be blank"],"first_name":["can't be blank"],"last_name":["can't be blank"]}}
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 22 (5 by maintainers)
@vishalTatvaSoft I’m pretty sure that you have solved this by now, but for other people who may come here for the first time, I was fighting with this today(rails 5 api too) and what you can do is override the
RegistrationsController
and thesign_up_params
method like this:Now you can use user key in the params again.
I feel list this should be on the documentation, as I had a simular issue. The resource name of my controller was
api_v1_user
and should beuser
. My solution was to override theresource_name
method like:debugging
devise_parameter_sanitizer
helper, result will bewith
@permitted={}
, eitherboth cases
@resource_name
is:api_user
, not justuser
, could this be the problem?You should tweak your devise_for accordingly.
For example, you may be able to keep things as is and pass
singular: true
(instead of custom controllers). Another idea is to move thedevise_for
call outside of your API and use the:path
option to customise the path.Check the output of
rake routes
to make sure you got things right.@carlosantoniodasilva that was the problem, as I had devise routes nested under api namespace in routes I had to send params into
api_user
key, notuser
. So I probably just need to override the registration routes, no luck so far:rake routes:
user_registration POST /users(.:format) api/users/registrations#create
No route matches [POST] “/api/users”, path_names: {sign_up: '/api/users'}
will generate/users/api/users(.:format)
Is there anyway to make the
api/users
route available to sign_up?