json post to devise cause 422 / Unprocessable entity

时间:2013-11-19 18:24:37

标签: ruby-on-rails angularjs devise

我正在使用角度并发布到RoR后端,并设计了auth。当我提交新用户进行创建时,我得到以下内容:

Started PUT "/api/user" for 127.0.0.1 at 2013-11-19 11:38:13 -0600
Processing by Devise::RegistrationsController#create as JSON
  Parameters: {"user"=>{"email"=>"alex@someemail.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "first_name"=>"alex", "last_name"=>"p"}, "registration"=>{"user"=>{"email"=>"alex@someemail.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "first_name"=>"alex", "last_name"=>"p"}}}
   (0.2ms)  BEGIN
  User Exists (0.8ms)  SELECT 1 AS one FROM "users" WHERE "users"."email" = 'alex@someemail.com' LIMIT 1
   (0.2ms)  ROLLBACK
Completed 422 Unprocessable Entity in 128ms (Views: 0.2ms | ActiveRecord: 7.4ms)

用户模型:

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :token_authenticatable, :confirmable,
  # :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable
  attr_accessible :first_name, :last_name, :email, :password, :password_confirmation, :remember_me, :last_check

end

我无法弄清楚发生了什么。我认为这是我发送的参数(或不发送?),但似乎一切都在那里。

1 个答案:

答案 0 :(得分:9)

我对日志的第一个想法是已经存在使用相同电子邮件的用户。否则,您可以使用httpclient(chrome中的curl或Postman或chrome中的Restclient)来查看响应是什么。

我对Angular不是很熟悉,但是如果你有权访问http响应,只需在控制台中输出即可。它应该告诉你验证错误。