On 24 May 2011 21:31, Kevin <[email protected]> wrote:
> I'm trying to create a function that will take input in the form "a12345678"
> and output text in the form "a12-34-5678" if and only if the input text is
> not in the form "adam smith"  The goal is to allow my users to enter either
> names separated by a space, or the student id number into a single search
> field 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).all
>    else
>      bar=insert_dashes(rec)
>      find_record(bar)
>  end
>  end
>
>
>
> If I try to enter a string of the for "a12345678" I am greeted with the
> following error:
>
> SystemStackError (stack level too deep):
>   app/controllers/students_controller.rb:19:in `find_student'

Have a look at the Rails Guide on Debugging to find how to use
ruby-debug to break into your code and inspect variables and follow
flow.  Then you can debug the method yourself to find what is going
wrong.  That way you will learn a lot for the future.

Colin

-- 
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