Validation on Update

In my model, I have the following declaration:

 validates_numericality_of :sortorder

If I try to input a non-numeric value (1x3 or whatever) during record
creation, I properly get an error and the record is not saved.

If I then go and use the update helper to input the same non-numeric
value, I don’t get any error message. Obviously, it can’t store an
non-numeric value into an integer field - but it simply ignores the new
value. If I change the sortorder using a numeric value, it (properly)
saves the new value to the database.

Obviously, I’m missing something. Why is my validates clause being
utilized on record creation, but not on record update?

As always, thanks in advance.
—Michael

Michael S. wrote:

In my model, I have the following declaration:

 validates_numericality_of :sortorder

If I try to input a non-numeric value (1x3 or whatever) during record
creation, I properly get an error and the record is not saved.

If I then go and use the update helper to input the same non-numeric
value, I don’t get any error message. Obviously, it can’t store an
non-numeric value into an integer field - but it simply ignores the new
value. If I change the sortorder using a numeric value, it (properly)
saves the new value to the database.

Obviously, I’m missing something. Why is my validates clause being
utilized on record creation, but not on record update?

As always, thanks in advance.
—Michael

post the code for the update and create actions in your controller,
perhaps the problem lies there.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs