未定义的方法' +'为零级

时间:2016-04-25 23:07:43

标签: javascript ruby-on-rails

我有这段代码:

<% @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):

我看不出有什么问题。如果有人可以帮助我。

1 个答案:

答案 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 %>