简体   繁体   English

疯狂的商业分类法错误

[英]Spree commerce taxonomies error

undefined method `each' for nil:NilClass nil:NilClass的未定义方法“ each”

<% max_level = Spree::Config[:max_level_in_taxons_menu] || 1 %>
  <nav id="taxonomies" class="sidebar-item" data-hook>

  <% @taxonomies.each do |taxonomy| %>
    <% unless taxonomy.name == 'Tags' %>
      <h6 class="taxonomy-root"><%= Spree.t(:shop_by_taxonomy, :taxonomy => taxonomy.name) %></h6>
      <%= taxons_tree(taxonomy.root, @taxon, Spree::Config[:max_level_in_taxons_menu] || 1) %>

This is the error i am getting and this is the code i updated to taxonomies.each.to_a not sure if that is right and how do i update the code so the server will run the new code instead of the older code? 这是我遇到的错误,这是我更新为taxonomies.each.to_a的代码,不确定是否正确,以及如何更新代码,以便服务器将运行新代码而不是旧代码?

Here is the updated code 这是更新的代码

<% max_level = Spree::Config[:max_level_in_taxons_menu] || 1 %>
<nav id="taxonomies" class="sidebar-item" data-hook>
  <% @taxonomies.each.to_a do |taxonomy| %>
    <% cache [I18n.locale, taxonomy, max_level] do %>
      <h6 class='taxonomy-root'><%= Spree.t(:shop_by_taxonomy, :taxonomy => taxonomy.name) %></h6>
      <%= taxons_tree(taxonomy.root, @taxon, max_level) %>
    <% end %>
  <% end %>
</nav>

Looks like what you're doing is forcing a nil object to an array, which will work, yt isn't an ideal solution. 看起来您正在执行的是将nil对象强制为数组,这将起作用,yt不是理想的解决方案。 You can wrap the whole thing in this: 您可以将整个内容包装在其中:

<% if @taxonomies && @taxonomies.any? %>
  #your code goes here
<% end %>

...which will check for the presence of a taxonomies variable and make sure it isn't an empty array before running your code. ...这将在运行代码之前检查分类法变量的存在,并确保它不是空数组。 As far as getting the code on the server goes, you'll have to post more info about your deployment setup and version control to answer that question. 就在服务器上获取代码而言,您必须发布有关部署设置和版本控制的更多信息才能回答该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM