1
votes

I had a problem sign in into rails using CURL with POST method. What I've type in terminal is

curl -H 'Content-Type: application/json' -X POST http://localhost:3000/users/sign_in -d '{"user": {"email": "[email protected]", "password": "abc12345"}}'

but it returned some kind of html/javascript file in terminal. And here is my registration controller code :

class RegistrationsController < Devise::RegistrationsController

    private

    def sign_up_params 
        params.require(:user).permit(:name, :email, :password)
    end

    def account_update_params 
        params.require(:user).permit(:name, :email, :password, :current_password)
    end

end

and this is result i got in terminal for CURL request:

http://localhost:3000/users/sign_in
Hostname was NOT found in DNS cache
Trying ::1...
Connected to localhost (::1) port 3000 (#0)
POST /users/sign_in HTTP/1.1
User-Agent: curl/7.37.1
Host: localhost:3000
Accept: application/json
Content-type: application/json
Content-Length: 58

upload completely sent off: 58 out of 58 bytes
HTTP/1.1 422 Unprocessable Entity 
Content-Type: text/html; charset=utf-8
Content-Length: 107406
X-Request-Id: afb62a3b-c193-4cda-be72-23c0af7d600f
X-Runtime: 0.208985
Server WEBrick/1.3.1 (Ruby/2.0.0/2014-05-08) is not blacklisted
Server: WEBrick/1.3.1 (Ruby/2.0.0/2014-05-08)
Date: Wed, 29 Jul 2015 15:14:29 GMT
Connection: Keep-Alive

I hope someone can help me regarding this problem. Thank you in advance.

1
What does the rails console say? What's the content of the body of the 422 response? - amiuhle

1 Answers

0
votes

Update: Try this instead:
http://blog.andrewray.me/how-to-set-up-devise-ajax-authentication-with-rails-4-0/


In config/initializers/devise.rb, add :json to accepted formats:

config.navigational_formats = [:"*/*", "*/*", :html, :json]

I suggest you also take a look at something like Postman to test JSON requests.