mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2025-11-09 01:14:23 -05:00
before_validation
This commit is contained in:
@@ -16,7 +16,7 @@ class Vehicle < ActiveRecord::Base
|
|||||||
attr_accessible :year, :make, :model, :qbo_customer_id, :notes, :vin
|
attr_accessible :year, :make, :model, :qbo_customer_id, :notes, :vin
|
||||||
validates_presence_of :year, :make, :model, :qbo_customer_id
|
validates_presence_of :year, :make, :model, :qbo_customer_id
|
||||||
|
|
||||||
before_save :decode_vin
|
before_validation :decode_vin
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
return "#{year} #{make} #{model}"
|
return "#{year} #{make} #{model}"
|
||||||
@@ -25,9 +25,9 @@ class Vehicle < ActiveRecord::Base
|
|||||||
private
|
private
|
||||||
|
|
||||||
def decode_vin
|
def decode_vin
|
||||||
if vin?
|
if self.vin?
|
||||||
decoder = Edmunds::Vin.new('2dheutzvhxs28dzukx5tgu47')
|
decoder = Edmunds::Vin.new('2dheutzvhxs28dzukx5tgu47')
|
||||||
vehicle = decoder.full(vin)
|
vehicle = decoder.full(self.vin)
|
||||||
self.year = vehicle['years'][0]['year']
|
self.year = vehicle['years'][0]['year']
|
||||||
self.make = vehicle['make']['name']
|
self.make = vehicle['make']['name']
|
||||||
self.model = vehicle['model']['name']
|
self.model = vehicle['model']['name']
|
||||||
|
|||||||
Reference in New Issue
Block a user