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
你的意思是你想要创建如果检查是真的摘要?或者如果检查是真的,你希望验证运行? –