0
我使用的軌道4.然後我的模型看起來像這樣如何在條件下運行「has_secure_password」?
class User < ActiveRecord::Base
has_secure_password
def checkup?
#Some Condition which returns true or false
self.attr == "apple"
end
end
在此我想has_secure_password
運行與checkup?
條件。我嘗試了所有可能的方法。
嘗試1
has_secure_password :if => checkup?
嘗試2
def checkup?
if condition_fails?
has_secure_password
end
end
任何幫助嗎?
你有什麼檢查? –
假設它是'self.attr ==「apple」' – Vicky
你的意思是你想要創建如果檢查是真的摘要?或者如果檢查是真的,你希望驗證運行? –