my_zipcode_gem
my_zipcode_gem copied to clipboard
Issue with def get_zip_data
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 <[email protected]>, 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
@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.