Ruby on rails 尝试在6个项目或类之后循环帮助程序时出现未定义的id错误
在我看来是这样的Ruby on rails 尝试在6个项目或类之后循环帮助程序时出现未定义的id错误,ruby-on-rails,ruby,loops,Ruby On Rails,Ruby,Loops,在我看来是这样的 <% elsif ["radio", "checkbox"].include?(part_child.display_type) %> <%= tick_tag_slice part_child%> <% end %> 在这里,我尝试在每个col-sm-2之后运行每个循环,当我尝试运行应用程序时,我得到了这个错误 数组的未定义方法“id”:0x007f0e282d61c0> 它在视图中显示的错误行,其中没有id 试图让t
<% elsif ["radio", "checkbox"].include?(part_child.display_type) %>
<%= tick_tag_slice part_child%>
<% end %>
在这里,我尝试在每个col-sm-2之后运行每个循环,当我尝试运行应用程序时,我得到了这个错误
数组的未定义方法“id”:0x007f0e282d61c0>
它在视图中显示的错误行,其中没有id
试图让t,但无法让它工作
请帮我解释一下。ArrayAch\u slice返回一个结果数组,因此需要重新计算块中的o变量,以给出六个条目
从以下文件:
我看不到上面代码中引用的id,但可能有一些方法依赖于o作为单个对象。您能给我们看一下您的数组内容吗?等等。。什么是part_child_option,就是part_child。option?不,没关系,没问题,在提问时遗漏了一段代码好的,更清楚。Thanks@ccai我不明白你的意思。我相信你是在问我上课的内容。这是imagesIt的o。照片:small-o是一个数组,不是一个对象。这没有意义。每个_片返回一个被分割成该大小的可枚举项的可枚举项,因此在该循环中,您需要使用photo方法获取每个o变量以获取实际对象。如果未引用id,我为什么会得到该错误。明白了。我错过了一个生成6列sm-2的循环,但我不知道该ID的引用。谢谢你,彼得
def tick_tag_slice(part_child)
render_type = part_child.display_type == "radio" ? "radio_button_tag" : "check_box_tag"
html = ""
part_child_option = parts_position(part_child.options)
part_child_option. each_slice(6) do |o|
html += "<div class = 'row'>"
html += "<div class='col-sm-2 uno_part_wrapper'>"
html += "<label class = 'p_name' for='#{attr_name}'>"
"data-part-type" =>"#{part_child.display_type}",
html += image_tag o.photo(:small), class: "tick_option_img",
"data-option-name" => o.name
html += "</label>"
html += "</div>"
html += "</div>"
end
html.html_safe
end
(1..10).each_slice(3) { |a| p a }
# outputs below
[1, 2, 3]
[4, 5, 6]
[7, 8, 9]
[10]