ruby on rails - Locking an attribute after it has a certain value -


I have a model, where it is given a certain position, then the situation can never be changed again By trying to check on the model by first_sev, what is the situation and increase the exception if it is set to fixed position

The problem is -

  def raise_if_exported if self Is .exported? Taking exception, "Can not change the exported invoice status" End End   

which works fine but when I initially set the position of export by doing the following - invoice.states = "exported" invoice. Save

An exception has been lifted because the situation has not already been exported to the model, DB (me )

Is that feature set to "export" When it is no way to prevent it from changing?

You can use a validator for your requirement

  Class invoice & lt; ActiveRecord :: Base validates_each: the situation is | Record, atri, value. If (atr ==: status and status_keyword and status_vas == "exported") record. Errors.ed (exported: status, "you can not touch it") end and end   

now

  invoice.tustus = " Gone "invoice save # success invoice.Testus =" new "invoice save # error    

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -