我有这段代码:
<% @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):
我看不出有什么问题。如果有人可以帮助我。
答案 0 :(得分: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 %>