curl - Rails 4 Api Users Post test failing -
i'm building blog in rails 4.2 api (for angular front end). i'm adding in users devise (overkill know), , controller tests pass everything. when try curl post request or try create user angular app, 406 not acceptable status code.
here create controller method:
def create user = user.new(user_params) if user.save render json: user, status: 201 else render json: { errors: user.errors }, status: 422 end end private def user_params params.require(:user).permit(:email, :password, :password_confirmation) end
i able create users rails console without problem.
here curl command keep trying:
curl -i -h 'accept: application/json' -h 'content-type: application/json' -x post -d '{"email":"person@mail.com","password":"12345678","password_confirmation":"12345678"}' http://api.myapi.dev/users
and have resource too:
api_users post /users(.:format) api/users#create {:subdomain=>"api"}
i can update user, , perform other action curl without issue, don't see problem here. appreciated.
according w3, 406
response is:
the resource identified request capable of generating response entities have content characteristics not acceptable according accept headers sent in request.
so when use curl, don't need send -h 'accept: application/json' -h 'content-type: application/json
, rails automatically render json result you. because have specified format.json
in controller.
rails expects send data in following way:
{ "users": { "email", "person@mail.com" }, ... }
while not sending users
when hit server curl command.
Comments
Post a Comment