试图使图像源成为对象参数之一

时间:2017-04-04 15:55:44

标签: html ruby-on-rails ruby

我在hmtl.erb文件中工作,尝试将图像源作为产品对象参数保存的链接。

<% @products.each do |categories,products| %>
<% products.each do |product| %>
<div class="container">    
<div class="row">
    <div class="col-sm-4">
        <div class="panel panel-primary">
            <div class="panel-heading">
                <%= link_to product.name, product_path(product.permalink) %></div>
                <%-# the image source link below is not working -%>
                <div class="panel-body"><img src= product.default_image.path class="img-responsive" style="height: 250 width:250" alt="Image"></div>
                <div class="panel-footer"><%= product.short_description %></div>
        </div>
    </div>
</div>
</div><br>
<%end%>

我已尝试将其放在引号中并执行@ product.default_image.path。我没有尝试过的任何作品

1 个答案:

答案 0 :(得分:0)

使用rails helper image_tag

<div class="panel-body">
  <%= image_tag(product.default_image.path, class: 'img-responsive') %>
</div>