Skip to content

Instantly share code, notes, and snippets.

@bsodmike
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bsodmike/478dea5dea2e1e62d793 to your computer and use it in GitHub Desktop.
Save bsodmike/478dea5dea2e1e62d793 to your computer and use it in GitHub Desktop.
Block helper in Rails 3
# 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 %>
@bsodmike
Copy link
Author

Credit to @Sailias - for helping me to skip using the capture helper
and @workmad3 - for the reminder of etag generation in production

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment