mardi 21 juin 2016

rails save record to table before validating?

So I have basically an invoice, and the post_status is nil and when its set to closed, users cant edit it anymore.

validate :post_status, :if => :opened?
def opened?
    if (post_status == 'Closed')
        errors.add(:base, "Already Closed")
        return false
    end
    return true
end

this is what i have but when I set to closed, it already starts validating it and so I cant really set it to closed. I want it to be able to set my post_status to closed, so then the next time I want to edit, I cant edit anymore because its already closed.

Aucun commentaire:

Enregistrer un commentaire