Reputation: 5197
I do have the image called 18.png
in assets/images/languages/
then I do have the attribute called language
Assuming, current_user.language = 18
How can I access and show the image in view?
Upvotes: 0
Views: 34
Reputation: 6346
Simply append the users language attribute to a relative language asset path inside your view.
<%= image_tag "languages/#{current_user.language}.png" %>
If this is something you're going to be using throughout your application you should move it into a helper method, e.g. :
def user_locale_tag
image_tag "languages/#{current_user.language}.png"
end
In your authentication system you'll want to ensure that current_user exists before hand.
Upvotes: 1