From 4a3b663333458dd99aa6fe09de7012844c64a32e Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Tue, 13 Jun 2017 21:49:10 -0400 Subject: [PATCH] Create vehicle.rb --- app/models/vehicle.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/models/vehicle.rb b/app/models/vehicle.rb index 165886a..fc02632 100644 --- a/app/models/vehicle.rb +++ b/app/models/vehicle.rb @@ -71,11 +71,10 @@ class Vehicle < ActiveRecord::Base # Force Upper Case for VIN numbers def vin=(val) - - val = val.to_s.gsub(/(?![A-HJ-NPR-Za-hj-npr-z\d])/,'') - - # The to_s is in case you get nil/non-string - write_attribute(:vin, val.to_s.upcase) + return if val.nil? + #strip VIN of all illegal chars (for barcode scanner) + val.to_s.upcase.gsub(/[^A-HJ-NPR-Za-hj-npr-z\d]+/,"") + write_attribute(:vin, val) end # search for a vin