I''ve got an student_id column in my Attendance table. The ID is found by searching with the student''s IDN in the before_create method: class Attendance < ActiveRecord::Base belongs_to :student validates_numericality_of :student_id, :only_integer => true def before_create self.student = Student.find_by_idn(student_id) end end This works just fine as long as the IDN that is entered is actually in the Student table. If it is not, I get an error stating student_id is NULL. How would I display "Student IDN not found" as an error message in my view? I''m new to programming and tried this but it does not work: def before_create s = Student.find_by_idn(student_id) if s = nil errors.add(:student_id, "is not a valid IDN") else self.student = s end end end Anyone have suggestions? Thanks for any help. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---