類似於this question爲常規設計寶石,使用devise_token_auth寶石顯示相同的結果 - 驗證錯誤出現兩次在json響應!?Rails 5.1:devise_token_auth返回2錯誤,當只有1應該被發現
從日誌:
Processing by DeviseTokenAuth::RegistrationsController#create as JSON
Parameters: {"name"=>"Mickey Mouse", "email"=>"[email protected]", "password"=>"[FILTERED]", "confirmPassword"=>"[FILTERED]", "confirm_success_url"=>"http://localhost:4200/register", "registration"=>{"name"=>"Mickey Mouse", "email"=>"[email protected]", "password"=>"[FILTERED]", "confirmPassword"=>"[FILTERED]", "confirm_success_url"=>"http://localhost:4200/register"}}
Unpermitted parameters: :confirmPassword, :confirm_success_url, :registration
Unpermitted parameters: :confirmPassword, :confirm_success_url, :registration
(0.2ms) BEGIN
User Exists (0.9ms) SELECT 1 AS one FROM "users" WHERE "users"."email" = $1 LIMIT $2 [["email", "[email protected]"], ["LIMIT", 1]]
(0.8ms) SELECT COUNT(*) FROM "users" WHERE "users"."provider" = $1 AND "users"."email" = $2 [["provider", "email"], ["email", "[email protected]"]]
(0.3ms) ROLLBACK
Completed 422 Unprocessable Entity in 247ms (Views: 0.7ms | ActiveRecord: 6.9ms)
注意,unpermitted_parameters線顯示兩次 - 這似乎預示着什麼奇怪的(這些線路不通過郵差顯示)。
我的用戶模型無關與標準引導多餘的,所以我絕對不會對我的模型2次的獨特性或存在驗證,並檢查寶石的源代碼,也不會出現有。
這裏是模型:
class User < ActiveRecord::Base
# Include default devise modules.
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:confirmable, :omniauthable
include DeviseTokenAuth::Concerns::User
end
如果我把從郵差這個端點,我得到了相同的結果,這裏是返回的JSON:
{
"status": "error",
"data": {
"id": null,
"account_id": null,
"provider": "email",
"uid": "",
"name": null,
"nickname": null,
"image": null,
"email": "[email protected]",
"created_at": null,
"updated_at": null
},
"errors": {
"email": [
"has already been taken",
"has already been taken"
],
"full_messages": [
"Email has already been taken",
"Email has already been taken"
]
}
}
Rails的API從Angular2稱爲使用angular2-token庫,但這顯然不是問題(從Postman得出結果)。
我怎麼能要麼找到這個原因,或者我怎麼能猴子修補寶石取下第2次故障?
UPDATE
如果我從模型中取出:validatable
,把我自己的驗證:
validates_uniqueness_of :email
我得到相同的結果,這是奇怪的。
這不是理想的,但我已經採取調用'uniq'在使用它們之前在錯誤消息數組上。 – pdoherty926
@ pdoherty926我很樂意這樣做,除了這是在設計寶石之上構建的寶石,我不得不想辦法從設計註冊控制器通過做一些猴子補丁來訪問它們善良(我從未做過) – rmcsharry