I am doing conditional validation for a numeric field like this in my
model
class AdditionalExam < ActiveRecord::Base
validates_presence_of :minimum_marks,:if=>:validate_grades?
belongs_to :additional_exam_group
def validate_grades?
puts"#{self.additional_exam_group.exam_type}"
end
def before_save
puts"#{self.additional_exam_group.exam_type}"
end
end
1. Note the belongs_to code.
2. The puts statement in the validate_grade method gives error, that
exam_type is undefined for nil class (i think additional_exam_group)
3. Same code works fine in the before_save method.
Why is this happening?
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.