Module: CountryFlags::Helper

Includes:
ActionView::Helpers::AssetTagHelper, ActionView::Helpers::AssetUrlHelper
Defined in:
lib/country_flags/helper.rb

Instance Method Summary collapse

Instance Method Details

#country_flag(country_code, options = {}) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/country_flags/helper.rb', line 22

def country_flag( country_code, options = {} )
  options = {format: :png}.merge(options)

  country_name = NormalizeCountry( country_code, to: :short )

  image_tag country_flag_path(country_code, options[:format]),
    alt: country_name, title: country_name
end

#country_flag_path(country_code, format = :png) ⇒ Object

returns path to flag image use ISO-3166 Alpha 2 country codes format can be :png or :gif



12
13
14
15
16
17
18
19
# File 'lib/country_flags/helper.rb', line 12

def country_flag_path( country_code, format = :png )
  unless [:png, :gif].include?(format)
    raise(ArgumentError, 'format must be :png or :gif')
  end

  path = "country_flags/#{format}/#{country_code.downcase}.#{format}"
  image_path path
end