Let me see if I got this right:
The model name is "student" and the attribute is called 
"student_number".
When a new student is created you want to make sure the student number 
has not been taken already, and if so, set it to the current maximum 
student number + 1.

I cant make much sense of the code you posted but you could put the code 
for it in a filter on the student model:

before_create(:check_student_number)

private

def check_student_number
  if(Student.find_by_student_number(self.student_number))
    self.student_number = Student.maximum(:student_number) + 1
  end
def
-- 
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 [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.

Reply via email to