Class: Location

Inherits:
ApplicationRecord show all
Defined in:
app/models/location.rb

Class Method Summary collapse

Class Method Details

.location_find_by_name(name) ⇒ Object


12
13
14
15
16
# File 'app/models/location.rb', line 12

def self.location_find_by_name(name)
  return nil if name.blank?
  name = name.downcase.strip
  where("name ~* ?", name).first
end

.location_find_or_create_by_name(name) ⇒ Object


18
19
20
21
22
23
24
# File 'app/models/location.rb', line 18

def self.location_find_or_create_by_name(name)
  name = name.strip
  unless (location = location_find_by_name(name))
    location = create(name: name)
  end
  location
end