Skip to content

Instantly share code, notes, and snippets.

@satomixx
Last active August 29, 2015 14:21
Show Gist options
  • Save satomixx/8314beed0bab9f2da10f to your computer and use it in GitHub Desktop.
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
$ curl -H "Content-Type: application/json" -d '{"user":{"email":"hoge@hoge.hoge","password":"12345678"}}' -X POST http://localhost:3000/api/v1/users
{"errors":{"email":["can't be blank"],"password":["can't be blank"]}}
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"}%
def sign_up_params
params.require(:user).permit(:email, :password, :password_confirmation)
end
def create
build_resource(sign_up_params)
super
end
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