Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with def get_zip_data #23

Open
theword opened this issue Feb 4, 2018 · 1 comment
Open

Issue with def get_zip_data #23

theword opened this issue Feb 4, 2018 · 1 comment

Comments

@theword
Copy link

theword commented Feb 4, 2018

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
@cmckni3
Copy link
Collaborator

cmckni3 commented Feb 4, 2018

@theword thanks for reporting this. The README is actually outdated and shows code for Rails 2. Yikes! 😱

I will see about updating it when I have a chance. A pull request would really help me out though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants