Class: SimpleAddress::City
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- SimpleAddress::City
- Defined in:
- app/models/simple_address/city.rb
Class Method Summary collapse
Instance Method Summary collapse
- #country_id ⇒ Object
- #country_id=(value) ⇒ Object
- #country_name ⇒ Object
- #region_name ⇒ Object
- #region_name=(value) ⇒ Object
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_id ⇒ Object
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_name ⇒ Object
25 26 27 |
# File 'app/models/simple_address/city.rb', line 25 def country_name value_of :country_name end |
#region_name ⇒ Object
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 |