简体   繁体   English

gem'zip-codes'未在rails4中获取法国的zip

[英]gem 'zip-codes' not fetching zip of france in rails4

Hello I am using gem 'zip-codes' to match the zip-code with given state and city its working fine for US country, state and city. 您好,我正在使用gem 'zip-codes'将邮政编码与给定的州和城市进行匹配,以使其适合美国国家/地区,州和城市。 But for FRANCE its not working it as in European countries we don't have states we have province so its not working for that. 但是对于法国来说,它没有像在欧洲国家那样奏效,所以我们没有州,因为我们拥有省份,所以它没有为此而努力。 I have written given code in my model: 我已经在模型中编写了给定的代码:

validate :zip_and_city_match, on: [:create, :update]

def zip_and_city_match
    @zip = ZipCodes.identify(self.zip)
    if @zip.present?
      unless self.state_code == @zip[:state_code] && self.city == @zip[:city]
        self.errors.add(:zip, 'Does not match the provided city and state')
      end
    else
      self.errors.add(:zip, 'Invalid Zip')
    end
end

If I give country = France, state_code= Île-de-France, city = Paris and zip = 75001 so it gives error Does not match the provided city and state . 如果我将country = France,state_code =法兰西岛,city = Paris和zip = 75001给出,则给出的错误与提供的城市和州不匹配 I had also tried http://blog.joshsoftware.com/2010/08/21/zipcode-validation-using-geokit-in-rails/ this but this also don't work for me. 我也尝试过http://blog.joshsoftware.com/2010/08/21/zipcode-validation-using-geokit-in-rails/但这对我也不起作用。 Please help me out how to solve this. 请帮助我解决该问题。 Thanks in advance. 提前致谢。

this gem 'zip-codes' only supports US zipcode. gem 'zip-codes'仅支持美国邮政编码。 So i think you should go for other solution. 所以我认为您应该寻求其他解决方案。 See this file of gem 'zip-codes' US.yml .For more information, you can go through the file of this gem zip-codes 请参阅此gem'zip gem 'zip-codes' codes'US.yml文件 。有关更多信息,您可以浏览此gem 邮政编码的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM