Reading Model data before update

Hi all,

here is the challenge:

I have this validation method, that basically prevents an object which billed = true to be updated:

  def before_update     if read_attribute(:billed)       errors.add_to_base('This service has already been billed for')     end     !read_attribute(:billed)   end

The above code does not work in case I do something like:

object = Model.find(:first) object.billed = true

because in my before_update filter I am reading the billed column, that now has 'true', so the validation returns false and the record is not saved.

The purpose of this validation is to prevent a record that has been marked billed to be changed. But how then am I going to update billed to true?

I've tried using self.service.update_attribute('billed', true), doest work. update_attribute_with_validation_skipping returns unknown method error.


Just find the old one:

old_model = Model.find id

and then verify some stuff on the old model.


I knew it was easy lol

Thanks a lot.