Just put 'puts rec' just after the 'def self.find_record(rec)' and see
what you get.

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'
>
> Rendered
> c:/jruby-1.6.1/lib/ruby/gems/1.8/gems/actionpack-3.0.7/lib/action_dispatch/middleware/templates/rescues/_trace.erb
> (18.0ms)
> Rendered
> c:/jruby-1.6.1/lib/ruby/gems/1.8/gems/actionpack-3.0.7/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb
> (41.0ms)
> Rendered
> c:/jruby-1.6.1/lib/ruby/gems/1.8/gems/actionpack-3.0.7/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb
> within rescues/layout (85.0ms)
>
> Can anyone explain what the problem might be or a better approach to
> accomplishing this particular task?
>
>
>
> --
> 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.
>

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