图像没有显示在Rails项目中

时间:2015-06-25 05:41:02

标签: 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')%>"><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>

2 个答案:

答案 0 :(得分:1)

他们都是影像,对吧?

为什么不使用image_pathimage_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>

Docs

image_path("rails.png")
# => "/assets/rails.png"

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

答案 1 :(得分:0)

您必须使用此帮助程序“&lt;%= image_tag('imagename')%&gt;”完成它。喜欢,

<%= 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" />

有关此图片代码帮助程序的详细信息,请访问API DOC