Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我确实有调用18.png图像assets/images/languages/
18.png
assets/images/languages/
那么我确实有一个名为language Assuming, current_user.language =的属性18
language
18
如何访问和显示视图中的图像?
只需将用户语言属性附加到视图内的相对语言资产路径即可。
<%= image_tag "languages/#{current_user.language}.png" %>
如果这是您要在整个应用程序中使用的东西,您应该将其移至辅助方法中,例如:
def user_locale_tag image_tag "languages/#{current_user.language}.png" end
在您的身份验证系统中,您需要确保 current_user 事先存在。