Last active
August 29, 2015 14:10
-
-
Save bsodmike/478dea5dea2e1e62d793 to your computer and use it in GitHub Desktop.
Block helper in Rails 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# FrontendHelper presentation PORO | |
def flag_for_country_code(country_code, &block) | |
country = ::Refinery::Professionals::GeoipCountry.find_by_country_code(country_code) | |
if country && country.available_locales.any? | |
flag_locale = country.available_locales.first | |
flag_url = "/#{flag_locale}" | |
country_name = country.name | |
yield(flag_url, country_name) | |
end | |
end | |
# In view | |
<% flags.each do |hsh| %> | |
<% flag_for_country_code(hsh[:country_code]) do |url, country_name| %> | |
<a href="<%= url %>" class="g--item g--two flag grad--dark-grey-inverted"> | |
<%= image_tag "flags/#{hsh[:asset_name]}.png", size: "80x44", alt: "" %> | |
<p><%= country_name %></p> | |
</a> | |
<% end if @available_countries.include?(hsh[:country_code]) %> | |
<% end %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Credit to @Sailias - for helping me to skip using the
capture
helperand @workmad3 - for the reminder of etag generation in production