Displaying 1 result from an estimated 1 matches for "find_record".
2011 May 24
4
Rails hates my recursive function
...eld and have the results be returned based on the format of the query.
I came up with the following code in my student model
def self.insert_dashes(term)
if /^([A-Z]|[a-z]|\d|-){11}$/.match(term)
term.insert 3, ''-''
term.insert 6,''-''
end
end
def self.find_record(rec)
if /^([A-Z]|[a-z]|\d|-){11}$/.match(rec)
student=Student.where(:studentID=>rec).all
elsif /^([A-Z\s]|[a-z\s])+$/.match(rec)
split=rec.split '' '',2
f_name=split.first
l_name=split.second
student=Student.where(:fname=>f_name,:lname=>l_name)....