我試圖讓Clearance與AWS Dynamo一起作爲後端商店。我遇到的問題是我無法通過而不是執行電子郵件唯一性驗證,因爲它無法通過SQL查詢執行標準ActiveRecord唯一性驗證,所以無法執行此操作。如何在清除中禁用電子郵件驗證
據the comments in the code,我應該能有我User
對象返回email_optional?
true
,並應禁用電子郵件的唯一性驗證。所以,我有:
class User < ApplicationRecord
include Dynamoid::Document
include Clearance::User
field :name
field :email
def email_optional?
puts 'yes, email is optional'
true
end
end
但是,當我嘗試創建一個用戶我得到一個錯誤,而且,更重要的是,不執行puts
:
$ rails c
Running via Spring preloader in process 18665
Loading development environment (Rails 5.1.3)
irb(main):001:0> u = User.new(name: 'ijd', email: '[email protected]', password: 'test')
ActiveRecord::StatementInvalid: Could not find table 'editor_development_users'
from (irb):1
更新:從回覆@spickermann提醒我,我應該注意到,我也試過沒有子類ActiveRecord::Base
(通過ApplicationRecord
)。它提供了不同的錯誤:
class User
include Dynamoid::Document
....
irb(main):002:0> reload!
Reloading...
=> true
irb(main):003:0> u = User.new(name: 'ijd', email: '[email protected]', password: 'test')
ArgumentError: Unknown validator: 'UniquenessValidator'
from app/models/user.rb:4:in `include'
from app/models/user.rb:4:in `<class:User>'
from app/models/user.rb:2:in `<top (required)>'
from (irb):3
感謝您的答覆。我在原答覆中應該提到我已經嘗試過,但我得到了一個不同的錯誤。我已經更新了上面的帖子。 –
@IanDickinson TIL,'UniquenessValidator'不是'ActiveModel :: Validations'的一部分。我更新了我的答案,以解決更新問題中的問題。 – spickermann