I have a form. One of the fields is zip code. If I fill out the form, here are the params:
Parameters: {"utf8"=>"✓", "authenticity_token"=>"fasdafdsafdsdsa/MKI/RGfds3=",
"profile"=>{"title"=>"profile title", "zip_code"=>"02155"}}
As you can see, the zip code is still in tact.
I have a custom zip code validation:
VALID_ZIP_CODE_REGEX= /\A[0-9]{5}(-[0-9]{4})?\z/ #Does not work for +4
validates :zip_code, format: { :with => VALID_ZIP_CODE_REGEX },
allow_blank: true, unless: 'dont_do_this?'
Here is the beginning of the method dont_do_this?
def dont_do_this
puts 'self: ' + self.inspect.to_s
end
and here is the output:
self: #<Profile id: 7, created_at: "2014-05-06 16:50:14", updated_at: "2014-08-21 17:43:35",
zip_code: 2155>
For some reason, the first zero of the zip code is stripped off. I can't figure out why. Does anyone know?