Use delegate to define delegations
This commit is contained in:
parent
a449e114f7
commit
49461aea32
|
@ -1,8 +1,12 @@
|
|||
require 'geokit'
|
||||
|
||||
class Thing < ActiveRecord::Base
|
||||
extend Forwardable
|
||||
include ActiveModel::ForbiddenAttributesProtection
|
||||
belongs_to :user
|
||||
def_delegators :reverse_geocode, :city, :country, :country_code,
|
||||
:full_address, :state, :street_address, :street_name,
|
||||
:street_number, :zip
|
||||
has_many :reminders
|
||||
validates :city_id, uniqueness: true, allow_nil: true
|
||||
validates :lat, presence: true
|
||||
|
@ -22,42 +26,6 @@ class Thing < ActiveRecord::Base
|
|||
@reverse_geocode ||= Geokit::Geocoders::MultiGeocoder.reverse_geocode([lat, lng])
|
||||
end
|
||||
|
||||
def street_number
|
||||
reverse_geocode.street_number
|
||||
end
|
||||
|
||||
def street_name
|
||||
reverse_geocode.street_name
|
||||
end
|
||||
|
||||
def street_address
|
||||
reverse_geocode.street_address
|
||||
end
|
||||
|
||||
def city
|
||||
reverse_geocode.city
|
||||
end
|
||||
|
||||
def state
|
||||
reverse_geocode.state
|
||||
end
|
||||
|
||||
def zip
|
||||
reverse_geocode.zip
|
||||
end
|
||||
|
||||
def country_code
|
||||
reverse_geocode.country_code
|
||||
end
|
||||
|
||||
def country
|
||||
reverse_geocode.country
|
||||
end
|
||||
|
||||
def full_address
|
||||
reverse_geocode.full_address
|
||||
end
|
||||
|
||||
def adopted?
|
||||
!user.nil?
|
||||
end
|
||||
|
|
|
@ -12,7 +12,7 @@ Rails.application.routes.draw do
|
|||
scope '/sidebar', controller: :sidebar do
|
||||
get :search, as: 'search'
|
||||
get :combo_form, as: 'combo_form'
|
||||
get :edit_profile , as: 'edit_profile'
|
||||
get :edit_profile, as: 'edit_profile'
|
||||
end
|
||||
|
||||
resource :reminders
|
||||
|
|
Loading…
Reference in New Issue