2016-04-25 49 views
1

我有這樣的代碼:未定義的方法 '+' 的無級

<% @accessories.each do |accessory|%> 
    <div> 
     <%= image_tag(accessory.firebrick_qcg.url , :"title" => accessory.part_number , :"alt" => accessory.description , :"data-size" => accessory.width.to_s + "," + accessory.height , :"data-size2" => accessory.width2.to_s + "," + accessory.height2 , :"data-img1" => accessory.firebrick_qcg.url , :"data-img2" => accessory.firebrick_qcr.url, :"data-img3" => accessory.firebrick_rg.url , class: "img-responsive") %> 
    </div> 
<% end %> 

我得到這個錯誤:

ActionView::Template::Error (undefined method `+' for nil:NilClass): 

Ican't看到什麼是錯的。如果有人能幫助我。

+0

似乎你已經通過'nil'到'image_tag'請用'哪個參數進行評估,以零 –

回答

0

我認爲在連接時出錯,使用"#{}"來連接ruby中的字符串。

保存前修復空格和額外的行。

<% @accessories.each do |accessory|%> 
    <div> 
     <%= image_tag(accessory.firebrick_qcg.url, 
     :"title" => accessory.part_number, 
     :"alt" => accessory.description, 
     :"data-size" => "#{accessory.width.to_s}, accessory.height", 
     :"data-size2" => "#{accessory.width2.to_s}, #{accessory.height2}", 
     :"data-img1" => accessory.firebrick_qcg.url, 
     :"data-img2" => accessory.firebrick_qcr.url, 
     :"data-img3" => accessory.firebrick_rg.url , 
     class: "img-responsive") %> 
    </div> 
<% end %> 
+0

pry'驗證謝謝@ 7urkm3n – user3472955