2017-04-04 4 views
0

イメージソースに製品オブジェクトのパラメータとして保存されているリンクを作成しようとしているhmtl.erbファイルで作業しています。イメージソースをオブジェクトのパラメータの1つにしようとしています

<% @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を実行しようとしました。私は未定義のメソッドエラーを与える作品

答えて

0

レールのヘルパーを使用しimage_tag

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

を試してみました何もありません。 "定義されていないメソッド' path for nil:NilClass " –

+0

あなたの' default_image'は 'nil'です。もう一つの問題です。 – Iceman

関連する問題