Create vehicle.rb

This commit is contained in:
2017-06-13 21:49:10 -04:00
committed by GitHub
parent e43635b5d8
commit 4a3b663333

View File

@@ -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