Use delegate to define delegations

This commit is contained in:
Erik Michaels-Ober 2014-08-15 02:16:19 +02:00
parent a449e114f7
commit 49461aea32
2 changed files with 5 additions and 37 deletions

View File

@ -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

View File

@ -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