Module: AddressConcern::Address
- Extended by:
- ActiveSupport::Concern
- Includes:
- AttributesSlice, InspectBase
- Defined in:
- lib/address_concern/address.rb
Defined Under Namespace
Modules: Base
Instance Method Summary collapse
- #states_for_country_str ⇒ Object
-
#validate_state_for_country ⇒ Object
═════════════════════════════════════════════════════════════════════════════════════════════════ Customizable validation (part 2 of 2) Defining here rather than in included block, so that it is actually defined on the module, which gives the consumer more flexibility on how to reuse the validation code.
Methods included from AttributesSlice
#attributes_except, #attributes_slice
Methods included from InspectBase
Instance Method Details
#states_for_country_str ⇒ Object
823 824 825 826 |
# File 'lib/address_concern/address.rb', line 823 def states_for_country_str return unless country_with_states? states_for_country.map(&:code).join(', ') end |
#validate_state_for_country ⇒ Object
═════════════════════════════════════════════════════════════════════════════════════════════════ Customizable validation (part 2 of 2) Defining here rather than in included block, so that it is actually defined on the module, which gives the consumer more flexibility on how to reuse the validation code. You can, for example, do this:
validate \
def validate_state_for_country
return unless addressable.is_a?(User)
super
end
814 815 816 817 818 819 820 821 |
# File 'lib/address_concern/address.rb', line 814 def validate_state_for_country return unless country_with_states? return unless state_code return if states_for_country.map(&:code).include? state_code errors.add self.class.state_code_attribute, :state_not_in_list, country_name: country_name, states_for_country: states_for_country_str # puts %(errors.messages=\n#{(errors.messages).pretty_inspect.indent(4)}) end |