将图像添加到 ruby on rails 中的布局 [英] Add image to layout in ruby on rails
问题描述
我想在我的 ruby on rails 项目的模板中添加一个图像,其中我目前拥有代码 <img src="../../../public/images/rss.jpg" alt="rss feed"/>
在布局 stores.html.erb
文件中,但是这似乎没有加载,因为它看起来好像缺少我的路线我不确定它应该是什么.
I would like to add an image in my template for my ruby on rails project where i currenly have the code <img src="../../../public/images/rss.jpg" alt="rss feed" />
in a the layout stores.html.erb
file however this doesn't seem to load as it looks like its missing a route which i'm not sure what its supposed to be.
有什么想法吗?
推荐答案
public
文件夹中的任何内容都可以在根路径 (/
) 中访问,因此请更改您的 img 标签阅读:
Anything in the public
folder is accessible at the root path (/
) so change your img tag to read:
<img src="/images/rss.jpg" alt="rss feed" />
如果您想使用 rails 标签,请使用:
If you wanted to use a rails tag, use this:
<%= image_tag("rss.jpg", :alt => "rss feed") %>
这篇关于将图像添加到 ruby on rails 中的布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!