Friday 30 October 2009

save! and save, update_attributes and update_attributes!

This little bugger ate an hour or so of my day. Had a model with validation on a telephone number field which it should fail if someone puts in letters etc.
For some reason I had changed the update to update_attributes! rather than leaving it as update_attributes (teach you to fiddle with things).
save!/update_attributes!/create! throws an error - and unless you have some way of catching it you will end up with
ActiveRecord::RecordInvalid (Validation failed: Name can't be blank, Name has already been taken, Main number only digits, ., +. (, ), allowed):

instead of the scaffold-like

Let that be a lesson

No comments:

Post a Comment