简体   繁体   中英

How can I access to assets/image

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?

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, eg :

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM