I am pretty confused by this issue: in my model, I am using a
before_validation callback and a validates_format_of method call.
My before_validation method does some attribute massaging to assign nil
to an attribute if it’s found to contain certain special characters. My
validates_format_of method has :allow_nil => true and should only fire
if none of the special characters are found.
So here’s where the confusion occurs: when I try to create a new record,
my validates_format_of method complains, saying that the data is
invalid. However, when I dump out what’s being validated, it looks like
my before_validation hasn’t fired yet - and thus it is trying to
validate on those disallowed characters, which of course doesn’t work
(nor should it).
Okay, so far, so good.
I’ve looked around on the forums and in my AWDWR book, and the consensus
seems to be that when you call @some_ar_object.save, there’s an
established hierarchy for how callbacks are fired:
before_validation
… (validates_whatever fires here?)
after_validation
…
before_save
before_create / before_update
INSERT / UPDATE OPERATION
…
That all makes sense as well. However, am I incorrect in assuming that
methods like “validates_whatever” get fired in between before_validation
and after_validation? That is my intuitive guess, but Rails doesn’t seem
to be behaving that way.
I’m sorry if there’s something really obvious I’m missing, but I’m
pretty confused right now. Any help is appreciated!
Thanks,
kodama