Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def check_vehicle(year, make, model, submodel)
- @year = Year.find_by_year(year)
- @make = Make.find_by_make(make)
- @model = Model.find_by_model(model)
- @submodel = Submodel.find_by_submodel(submodel)
- case
- when (@year == nil or @make == nil or @model == nil or @submodel == nil)
- @vehicle_exists = 'Nil error'
- when !Year.exists?(:year => year)
- @vehicle_exists = 'Year error'
- when !Make.exists?(:make => make)
- @vehicle_exists = 'Make error'
- when !Model.exists?(:model => model)
- @vehicle_exists = 'Model error'
- when !Submodel.exists?(:submodel => submodel)
- @vehicle_exists = 'Submodel error'
- # when clause only runs when none of the varibles are nil to avoid logic error
- when !Vehicle.exists?(:year_id => @year.id, :make_id => @make.id, :model_id => @model.id, :submodel_id => @submodel.id)
- @vehicle_exists = 'Vehicle error'
- else
- @vehicle_exists = 'ok'
- end
- end
Add Comment
Please, Sign In to add comment