On 16 March 2011 06:43, mnj [email protected] wrote:
- Note the belongs_to code.
Firstly, (since the validate_grades? method does no actual checking
for validation…) I’m assuming you’re using those “puts” as debugging
aids. If so, it would be better to actually use the Ruby debugging
functionality, and leave your validation code in place.
- The puts statement in the validate_grade method gives error, that
exam_type is undefined for nil class (i think additional_exam_group)
That’s letting you know that there isn’t an associated
You could change the validate_grades?  to check for an
additional_exam_group before progressing.
return false unless self.additional_exam_group
return true if … # some validation code here…
If the additional_exam_group is mandatory regardless, add a:
- Same code works fine in the before_save method.
Why is this happening?
Is there any other code in the model that you’ve stripped-out for this
example? Maybe something is messing with the additional_exam_group
between the validate and before_save callbacks?
 Given the question mark, I’d call it “valid_grades?” to read
nicely, but that’s just personal preference