Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html Rails项目中未显示图像_Html_Ruby On Rails - Fatal编程技术网

Html Rails项目中未显示图像

Html Rails项目中未显示图像,html,ruby-on-rails,Html,Ruby On Rails,我在一个新的rails项目中放置了一些图像。但和我之前的html页面一样,这些图像不会显示在rails应用程序中 查看图像的页面代码 <div class="item"><a href="<%= asset_path('01.jpg')%>" title="This is an image title" data-lightbox-gallery="gallery1" data-lightbox-hidpi="<%= asset_path('1@2x.jpg

我在一个新的rails项目中放置了一些图像。但和我之前的html页面一样,这些图像不会显示在rails应用程序中

查看图像的页面代码

 <div class="item"><a href="<%= asset_path('01.jpg')%>" title="This is an image title" data-lightbox-gallery="gallery1" data-lightbox-hidpi="<%= asset_path('1@2x.jpg')%>"><img src="<%= asset_path('01.jpg')%>" class="img-responsive" alt="img"></a></div>
 <div class="item"><a href="<%= asset_path('02.jpg')%>" title="This is an image title" data-lightbox-gallery="gallery1" data-lightbox-hidpi="<%= asset_path('2@2x.jpg')%>"><img src="<%= asset_path('02.jpg')%>" class="img-responsive " alt="img"></a></div>
 <div class="item"><a href="<%= asset_path('03.jpg')%>" title="This is an image title" data-lightbox-gallery="gallery1" data-lightbox-hidpi="<%= asset_path('3@2x.jpg')%>"><img src="<%= asset_path('03.jpg')%>" class="img-responsive " alt="img"></a></div>

您必须使用此帮助程序“”来完成此操作。像

<%= image_tag("image.jpg") %>
// output:
<img alt="Image" src="/assets/image.jpg" />

<%= image_tag("/logos/logo.png", width: '32', height: '32', alt: 'Site Logo', class: "logo") %>

// output: 
<img alt="Site Logo" src="/assets/logos/logo.png" width="32" height="32" class="logo" />

//输出:
//输出:

有关此图像标记帮助器的更多信息,请访问

它们都是图像,对吗

为什么不使用
image\u path
image\u url
类似:

<div class="item"><a href="<%= image_path('01.jpg')%>" title="This is an image title" data-lightbox-gallery="gallery1" data-lightbox-hidpi="<%= asset_path('1@2x.jpg')%>"><img src="<%= image_path('01.jpg')%>" class="img-responsive" alt="img"></a></div>
 <div class="item"><a href="<%= image_path('02.jpg')%>" title="This is an image title" data-lightbox-gallery="gallery1" data-lightbox-hidpi="<%= asset_path('2@2x.jpg')%>"><img src="<%= image_path('02.jpg')%>" class="img-responsive " alt="img"></a></div>
 <div class="item"><a href="<%= image_path('03.jpg')%>" title="This is an image title" data-lightbox-gallery="gallery1" data-lightbox-hidpi="<%= asset_path('3@2x.jpg')%>"><img src="<%= image_path('03.jpg')%>" class="img-responsive " alt="img"></a></div>

您必须将此帮助器标记放入视图文件中。像任何ERB模板文件一样。这个助手将从“assets/image”文件夹中获取图像。甚至你也可以用这个助手提供额外的类或东西。这很有帮助,请访问Rails指南。或者我给出的链接。请随意提出更多问题。请记住更新答案或将其作为解决方案检查。它不再起作用了。我的回购协议只有6,所以我不能更新你的答案。你是说,图像助手不起作用?你在告诉我什么。你的图像放在app/assets/images文件夹中…对吗?是的。我的图像放在app/assets/images文件夹中尝试执行
http://localhost:3000/01.jpg
在浏览器中,是否希望图像作为链接?不起作用。这部分代码是我的仪表板代码。
image_path("rails.png")
# => "/assets/rails.png"

image_url("rails.png")
# => "http://www.example.com/assets/rails.png"