Class: SimpleAddress::City

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/simple_address/city.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.search(params) ⇒ Object



7
8
9
10
11
# File 'app/models/simple_address/city.rb', line 7

def self.search(params)
  where(region_id: params[:region_id]).where(
    'name LIKE ?', "#{params[:name]}%"
  )
end

Instance Method Details

#country_idObject



21
22
23
# File 'app/models/simple_address/city.rb', line 21

def country_id
  region.country_id if region
end

#country_id=(value) ⇒ Object



13
14
15
16
17
18
19
# File 'app/models/simple_address/city.rb', line 13

def country_id=(value)
  if region
    region.update(country_id: value)
  else
    self.region = Region.create(country_id: value)
  end
end

#country_nameObject



25
26
27
# File 'app/models/simple_address/city.rb', line 25

def country_name
  value_of :country_name
end

#region_nameObject



29
30
31
# File 'app/models/simple_address/city.rb', line 29

def region_name
  value_of :name
end

#region_name=(value) ⇒ Object



33
34
35
36
37
38
39
# File 'app/models/simple_address/city.rb', line 33

def region_name=(value)
  if region
    region.update(name: value)
  else
    self.region = Region.where(name: value).first_or_create
  end
end