search for a vehicle by vin, make, model, or year, plus sql sanitization

This commit is contained in:
ricky committed 2026-02-21 08:33:59 -05:00
1 parent a73b6cd438
commit 6db87dd551
3 files changed
+6 -5

No files matched your search

+4 -3
View File
@@ -50,9 +50,10 @@ class Vehicle < ActiveRecord::Base
write_attribute(:vin, val)
end
# search for a vin
def self.search(search)
where("vin LIKE ?", "%#{search}%")
# search for a vehicle by vin, make, model, or year
def self.search(query)
q = sanitize_sql_like(query)
where("vin LIKE ? OR make LIKE ? OR model LIKE ? OR year LIKE ?", "%#{q}%", "%#{q}%", "%#{q}%", "%#{q}%")
end
# decodes a vin and updates self