Skip to content

Issue with def get_zip_data #23

@theword

Description

@theword

Following the documentation on AJAX/JQUERY functionality.
Received the following Error:
wrong number of arguments (given 2, expected 1)

It appeared Zipcode.find_by_code only takes one argument. The Zip Code. Also changed the line on finding counties to @counties = County.first(@zipcode.county_id)

Updated the code below as the following and it is returning the hash on the get call.

 def get_zip_data
    puts 'TEST'
    puts params
    @zipcode = Zipcode.find_by_code(params[:code])
    if @zipcode
      puts 'ZIPCODE---'
      pp @zipcode
      @counties = County.first(@zipcode.county_id)
      data = {
          'state' => @zipcode.state.abbr,
          'county' => @zipcode.county.name,
          'city' => @zipcode.city.titleize
      }
      render :text => data.to_json
    else
      if params[:code].blank?
        return true
      else
        if params[:code].is_zipcode?
          data = {
              'err' => "Could not find Zipcode [#{params[:code]}].  If this is a valid zipcode please notify support <support@mydomain.com>, so we can update our database."
          }
        else
          data = {
              'err' => "[#{params[:code]}] is not a valid Zipcode."
          }
        end
        render :text => data.to_json
      end
    end
  end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions