franckverrot / activevalidators

Collection of ActiveModel/ActiveRecord validators
https://rubygems.org/gems/activevalidators
MIT License
306 stars 49 forks source link

Postal code validator creates `undefined method 'match' for 12345:Fixnum` #96

Closed goulvench closed 8 years ago

goulvench commented 8 years ago

Hi,

I'm using ActiveValidator v4.0.0 in a project using Rails v5.0.0.1, ruby v2.3.1. I added the following to config/application.rb (inside the Class Application block):

ActiveValidators.activate(:email, :phone, :postal_code, :date)

But when I add validates :delivery_address_postcode, postal_code: { country: :fr } to my model and save data or run tests I get the following error:

NoMethodError:
        undefined method `match' for 86637:Fixnum
        Did you mean?  catch

Any idea why that happens? Is there something else to configure?

alyssais commented 8 years ago

Looks like activevalidators should be converting the postal code to a string before trying to validate it.

alyssais commented 8 years ago

@goulvench Could you try replacing activevalidators in your Gemfile with this, and let me know if that fixes it?

gem 'activevalidators', github: 'penman/activevalidators', branch: 'numeric_postal_code'
goulvench commented 8 years ago

Yes! Thank you, that works like a charm. My colleague told me to use strings instead for post codes in case we need to handle addresses outside of France, which would also solve that problem, but I believe your fix should be in the Gem nevertheless.

alyssais commented 8 years ago

Great! When this issue is closed you can change your Gemfile back to normal.

franckverrot commented 8 years ago

Salut @goulvench,

Thanks for reporting it. @penman just fixed the issue and I just released a new version on Rubygems 1. Tell us if it's fixed for you.

Merci! Franck

goulvench commented 8 years ago

Works great! Thanks @penman and @franckverrot for your quick response!