私は両方のapiとWebアプリケーションのためにdeviseを使用しています。 Webアプリは完璧に動作します。 ajaxでユーザーを作成しようとすると、機能しません。deviseは、jsonで作業していないユーザーを作成します。それは、電子メールが空であると言っている
$.ajax({
type: "POST",
url: 'http://localhost:3000/api/users',
data: JSON.stringify({user: {email: '[email protected]', password: 'password', password_confirmation: 'password'}}),
dataType: "json",
contentType: "application/json; charset=utf-8"
});
次responsetextが返されます:ここで
"{"errors":{"email":["can't be blank"],"password":["can't be blank"]}}"
はログです:ここでは
Started POST "/api/users" for ::1 at 2016-08-13 15:44:59 -0400
ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
application controller
yolo
Processing by RegistrationsController#create as JSON
Parameters: {"user"=>{"email"=>"[email protected]", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "registration"=>{"user"=>{"email"=>"[email protected]", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}}}
IN CREATE
(0.1ms) begin transaction
(0.1ms) rollback transaction
Completed 422 Unprocessable Entity in 40ms (Views: 1.3ms | ActiveRecord: 0.5ms)
ルートされています
devise_for :users
namespace :api, defaults: { format: :json } do
devise_for :users, controllers: {registrations: "registrations"}, :defaults => { :format => :json }
end
ここではAjaxのリクエストがあります私はを使用しています210それはそれとは関係がないはずです。これをどうやって解決するのですか?
ありがとうございますが、フォームを送信しようとしていません。私は私のサーバーにjson要求を送ることができる人が必要です。 jsonがサーバーに正しく当たっているようです。レールが使っている方法と関係していると思います。 – Philip7899
あなたが送信したデータに電子メール属性が存在するかどうかを調べ、テストします。 –
どうすればよろしくお願いします。 – Philip7899