我希望在我的application.html.erb文件中放置一个图像,以便它出现在每个页面上。图像位于public/legend.jpg
中,我的application.html.erb中的代码为:
<img src="legend.jpg"/>
这段代码在我的根页面加载图像,但是当我移动到一个嵌套的url,如:
http://localhost:3000/section/32
我得到以下错误:
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
http://localhost:3000/section/legend.jpg
我试过使用每一个国王的rails助手,但我似乎不能得到的图像是从每个url可用。感谢所有的帮手!
编辑:当它在公共文件夹中时,照片会加载,但只能在根url中加载…
使用image_tag
helper:
<%= image_tag 'legend.jpg' %>
http://apidock.com/rails/ActionView/Helpers/AssetTagHelper/image_tag 你可以把所有的图片放到assets/images/legend.jpg
然后,你可以使用<%= image_tag 'legend.jpg' %>,然后应该就好了。
你应该这样做,
<img src="/assets/legend.jpg"/>
有关详细信息,请参阅资产管道文档