From b002730a95601586f347e5e864ee9b25d3f767b7 Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Mon, 9 May 2016 06:46:48 -0400 Subject: [PATCH] Update vehicle.rb --- app/models/vehicle.rb | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/app/models/vehicle.rb b/app/models/vehicle.rb index 29857b8..cd2f8f7 100644 --- a/app/models/vehicle.rb +++ b/app/models/vehicle.rb @@ -11,10 +11,15 @@ class Vehicle < ActiveRecord::Base unloadable + belongs_to :customer + attr_accessible :year, :make, :model, :customer, :notes, :vin + validates_presence_of :customer validates :vin, uniqueness: true + validates :year, numericality: { only_integer: true } + before_save :decode_vin after_initialize :get_details @@ -39,7 +44,7 @@ class Vehicle < ActiveRecord::Base # returns the drive of the vehicle i.e. 2 wheel, 4 wheel, ect. def drive - return @details['drivenWheels'] if @details + return @details['drivenWheels'].to_s.upcase if @details end # returns the number of doors of the vehicle @@ -48,8 +53,21 @@ class Vehicle < ActiveRecord::Base end # Force Upper Case for VIN numbers - def self.vin=(val) - self.vin = val.upcase + def make=(val) + # The to_s is in case you get nil/non-string + write_attribute(:make, val.to_s.titleize) + end + + # Force Upper Case for VIN numbers + def model=(val) + # The to_s is in case you get nil/non-string + write_attribute(:model, val.to_s.titleize) + end + + # Force Upper Case for VIN numbers + def vin=(val) + # The to_s is in case you get nil/non-string + write_attribute(:vin, val.to_s.upcase) end private