mirror of
https://github.com/internetee/registry.git
synced 2025-08-05 09:21:43 +02:00
Refactored contact attribute assignment
This commit is contained in:
parent
5b91acb343
commit
6bcf508fac
7 changed files with 94 additions and 33 deletions
|
@ -1,4 +1,20 @@
|
|||
class Address < ActiveRecord::Base
|
||||
belongs_to :contact
|
||||
belongs_to :country
|
||||
|
||||
class << self
|
||||
def extract_attributes ah, type=:create
|
||||
address_hash = {}
|
||||
address_hash = ({
|
||||
country_id: Country.find_by(iso: ah[:cc]).try(:id),
|
||||
city: ah[:city],
|
||||
street: ah[:street][0],
|
||||
street2: ah[:street][1],
|
||||
street3: ah[:street][2],
|
||||
zip: ah[:pc]
|
||||
}) if ah.is_a?(Hash)
|
||||
|
||||
address_hash.delete_if { |k, v| v.nil? }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue