Guest User

Untitled

a guest
Jun 21st, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. def check_vehicle(year, make, model, submodel)
  2. @year = Year.find_by_year(year)
  3. @make = Make.find_by_make(make)
  4. @model = Model.find_by_model(model)
  5. @submodel = Submodel.find_by_submodel(submodel)
  6. case
  7. when (@year == nil or @make == nil or @model == nil or @submodel == nil)
  8. @vehicle_exists = 'Nil error'
  9. when !Year.exists?(:year => year)
  10. @vehicle_exists = 'Year error'
  11. when !Make.exists?(:make => make)
  12. @vehicle_exists = 'Make error'
  13. when !Model.exists?(:model => model)
  14. @vehicle_exists = 'Model error'
  15. when !Submodel.exists?(:submodel => submodel)
  16. @vehicle_exists = 'Submodel error'
  17. # when clause only runs when none of the varibles are nil to avoid logic error
  18. when !Vehicle.exists?(:year_id => @year.id, :make_id => @make.id, :model_id => @model.id, :submodel_id => @submodel.id)
  19. @vehicle_exists = 'Vehicle error'
  20. else
  21. @vehicle_exists = 'ok'
  22. end
  23. end
Add Comment
Please, Sign In to add comment