accessory.description , :"data-size" => acc-6ren">
gpt4 book ai didi

javascript - Nil 类的未定义方法 '+'

转载 作者:行者123 更新时间:2023-11-28 06:06:02 27 4
gpt4 key购买 nike

我有这个代码:

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

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

最佳答案

我认为连接时出现错误,请使用 "#{}" 在 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 %>

关于javascript - Nil 类的未定义方法 '+',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36852634/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com