I have ~ 500+ flag images that I previously kept in public/images/flags/
and public/images/flags_small/
. For each country in my Country model, I store the :iso_code
, which is the same as the name of the flag image that corresponds to it. For example, mx.png is the name of the Mexican flag because mx is the two-letter ISO code for Mexico.
I previously had a helper method that would return the html to display the image based on the iso code of the country and whether I wanted the large or small flag.
With Rails 3.1, to comply with the asset pipeline, I'm under the impression that those images should go into the app/assets/images
folder. Following from this:
Edit: solution The answer below was correct, but I didn't want to type that much code each time,so I created two helper methods:
def flag(country)
image_tag('/assets/flags/' + country.iso_code.downcase + '.png')
end
def small_flag(country)
image_tag('/assets/flag_small/' + country.iso_code.downcase + '.png')
end
Yes, you can
For example: <%= image_tag 'flags/uk.gif' %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With