Last active
August 29, 2015 14:21
-
-
Save satomixx/8314beed0bab9f2da10f to your computer and use it in GitHub Desktop.
RailsでJSON APIのバックエンドを作っていたら、Deviseの認証周りで422 Unprocessable Entityエラーを吐いてしまった場合 ref: http://qiita.com/tsumekoara/items/9a6da4a495af863bebf5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ curl -H "Content-Type: application/json" -d '{"user":{"email":"hoge@hoge.hoge","password":"12345678"}}' -X POST http://localhost:3000/api/v1/users |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"errors":{"email":["can't be blank"],"password":["can't be blank"]}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -H "Content-Type: application/json" -d '{"user":{"email":"hoge@hoge.hoge","password":"12345678"}}' -X POST http://localhost:3000/api/v1/users | |
{"id":1,"email":"hoge@hoge.hoge","authentication_token":null,"created_at":"2015-04-12T09:41:31.842Z","updated_at":"2015-04-12T09:41:31.881Z"}% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sign_up_params | |
params.require(:user).permit(:email, :password, :password_confirmation) | |
end | |
def create | |
build_resource(sign_up_params) | |
super | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :api, format: 'json' do | |
namespace :v1 do | |
devise_for :users, controllers: { | |
sessions: 'api/v1/users/sessions', | |
registrations: 'api/v1/users/registrations', | |
passwords: 'api/v1/users/passwords' | |
} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment