Sha256: b5fe01a7f07b282f726a2e6e99e55183be5bce8950737ac12d3594f35899ebbb

Contents?: true

Size: 772 Bytes

Versions: 3

Compression:

Stored size: 772 Bytes

Contents

module ShoppingCart
  module AddressesHelper
    def error?(type, field)
      return unless correct_type?(type)

      @address.errors.include?(field)
    end

    def error_message(type, field)
      return unless correct_type?(type)

      @address.errors.messages[field][0] if @address
    end

    def saved_value(type, field)
      address = address(type)
      return @address[field] if @address.try(:[], field) && correct_type?(type)

      address[field] if address
    end

    private

    def address(type)
      return current_user.billing_address if type == 'ShoppingCart::BillingAddress'

      current_user.shipping_address if type == 'ShoppingCart::ShippingAddress'
    end

    def correct_type?(type)
      @address.try(:type) == type
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
loker-shopping-cart-0.1.3 app/helpers/shopping_cart/addresses_helper.rb
loker-shopping-cart-0.1.2 app/helpers/shopping_cart/addresses_helper.rb
loker-shopping-cart-0.1.1 app/helpers/shopping_cart/addresses_helper.rb