SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    observe_field problems

    I'm full of problems tonight. a bunch I've solved by myself, but this one has me a bit stumped. I've never used the AJAX integration of RoR before, so thats part of the problem.

    I'm using code the OnLAMP Ajax on Rails tutorial as an example..

    What I'm trying to do is have a field for users to enter a zip code, after which, a select box will fill with all the schools within that zip code.

    /login/register.rhtml
    Code:
    <label for="school_zip">School Zip Code:</label><input type="text" name="school_zip" id="school_zip" size="5" />
          <%= observe_field(:school_zip, :update=>"school_select",
                           :url => { :action => :find_schools_from_zip} ) %>
          <label for="user_school_id">School Name:</label><br /><select id="school_select"></select>
    login_controller
    Code:
      ...
     def find_schools_from_zip
        if(params[:school_zip].length == 5)
          schools = School.find(:all, :conditions=> ["zipcode = ? and active = 'Y'", params[:school_zip]])
          schools.each do |s|
            options += "<option value=\"" + s.id + "\">" + s.name + "</option>"
          end
        end
        render_text options
      end
      ...
    I'm getting a nil exception from the params[:schools_zip].length
    saying it is nil.length, and in the paramters at the bottom of the error page, it is showing Paramters { "55455" => "" } 55455, being the zip code I put into the zipcode text field. umm/? how do I access this data when it is acting as the key?

  2. #2
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try adding :with => 'school_zip' to the call to observe_field.

  3. #3
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that did the trick! thank you very much.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •