app/models/addresses/address.rb in addresses-1.0.11 vs app/models/addresses/address.rb in addresses-2.0
- old
+ new
@@ -1,19 +1,22 @@
+# frozen_string_literal: true
+
module Addresses
class Address < ActiveRecord::Base
belongs_to :zipcode
belongs_to :addressable, polymorphic: true
validates :number, presence: true
- validates :zipcode_id, presence: true, if: Proc.new{|a| a.try(:zipcode).try(:street).blank? }
- delegate :street, :neighborhood, :city, to: :zipcode
+ validates :zipcode_id, presence: true, if: Proc.new { |a| a.try(:zipcode).try(:street).blank? }
+ delegate :street, :neighborhood, :city, to: :zipcode, allow_nil: true
accepts_nested_attributes_for :zipcode, allow_destroy: false
def to_s
to_s = "#{street}, #{number}"
to_s += ", #{neighborhood.name}" if neighborhood
to_s += " - #{city.name}" if city
to_s += "/#{city.state.acronym}" if city && city.state
+ to_s
end
end
end