所以我基本上有一张发票,post_status是零,当它设置为关闭时,用户不能再编辑它。在验证之前,rails将记录保存到表中?
validate :post_status, :if => :opened?
def opened?
if (post_status == 'Closed')
errors.add(:base, "Already Closed")
return false
end
return true
end
这就是我,但是当我设置为关闭的时候,就已经开始验证它,所以我真的不能把它设置为关闭状态。我希望它能够将我的post_status设置为关闭状态,然后在下一次我想要编辑时,我不能编辑它,因为它已经关闭了。
它给我的错误,它说需要提供中只会验证至少一个验证 – Oscar
取出秒,但,当我将它设置为关闭,验证开始踢在已其中犯规让我将其设置为关闭。因为它已经检测到,所以表格将不会被保存为关闭 – Oscar
谢谢你指出。我更新了答案 –