2

我已经被这个问题困了一个星期。如果你能弄明白的话,我会给你寄一瓶苏格兰威士忌。严重的是,它来贿赂。

taxons#show我正在渲染一个产品部分,_products.html.erb它列出了表格上的所有产品到分类单元控制器的显示视图。当您单击产品时,默认情况下,应用程序会将用户重定向到products#show,在此处_cart_local.html.erb呈现部分以显示“添加到购物车”选项。

但是taxons#show,当单击产品时,我会打开一个灯箱,因此用户不必离开页面。灯箱代码在里面_products.html.erb,我正在尝试_cart_form.html.erb在灯箱内部进行渲染。当我这样做时,我得到“堆栈级别太深”错误并且taxons#show不会渲染。

但是购物车在products#how. 我@product将部分更改为 just product。那没有帮助。我渲染了一个空的部分并加载了页面,这让我认为问题出在_cart_local(但为什么它会渲染products#show?)。

然后我取出了开始表单标记和结束 div/end 标记之间的所有代码,页面也被渲染了,这让我觉得它在那个块中,但我不能再把它缩小了。我被困住了

这是 的代码_cart_local,如果我取出<!-- Here --><!-- AND HERE -->注释之间的代码,页面将呈现:

<%= form_for :order, :url => populate_orders_path do |f| %>
<div id="inside-product-cart-form" data-hook="inside_product_cart_form" itemprop="offers" itemscope itemtype="http://schema.org/Offer">

<% if product.has_variants? %>  <!-- HERE --> 
  <div id="product-variants" class="columns five alpha">
    <h6 class="product-section-title"><%= t(:variants) %></h6>
    <ul>
      <% has_checked = false
      product.variants.active(current_currency).each_with_index do |v,index|
        next if v.option_values.empty? || (!v.in_stock && !Spree::Config[:show_zero_stock_products])
        checked = !has_checked && (v.in_stock || Spree::Config[:allow_backorders])
        has_checked = true if checked %>
        <li>
          <%= radio_button_tag "products[#{product.id}]", v.id, checked, :disabled => !v.in_stock && !Spree::Config[:allow_backorders], 'data-price' => v.price_in(current_currency).display_price %>
          <label for="<%= ['products', product.id, v.id].join('_') %>">
            <span class="variant-description">
              <%= variant_options v %>
            </span>
            <% if variant_price v %>
              <span class="price diff"><%= variant_price v %></span>
            <% end %>
          </label>
        </li>
      <% end%>
    </ul>
  </div>
<% end%>

<% if product.price_in(current_currency) and !product.price.nil? %>  
  <div data-hook="product_price" class="columns five <% if !product.has_variants? %> alpha <% else %> omega <% end %>">

    <div id="product-price">
      <h6 class="product-section-title"><%= t(:price) %></h6>
      <div><span class="price selling" itemprop="price"><%= product.price_in(current_currency).display_price %></span></div>
    </div>

    <div class="add-to-cart">
      <% if product.on_sale? %>      
        <%= number_field_tag (product.has_variants? ? :quantity : "variants[#{product.master.id}]"),
          1, :class => 'title', :in => 1..product.on_hand, :min => 1 %>
        <%= button_tag :class => 'large primary', :id => 'add-to-cart-button', :type => :submit do %>
          <%= t(:add_to_cart) %>
        <% end %>
      <% else %>
        <%= content_tag('strong', t(:out_of_stock)) %>
      <% end %>
    </div>
  </div>
<% else %>
    <div id="product-price">
      <br>
      <div><span class="price selling" itemprop="price"><%= t('product_not_available_in_this_currency') %></span></div>
    </div>
<% end %> <!-- AND HERE -->   

</div>
<% end %>

_products.html.erb是加载所有产品的文件,包含灯箱,并具有渲染车部分代码:

<div class="overlay-container">
</div>
<%
 paginated_products = @searcher.retrieve_products if params.key?(:keywords)
 paginated_products ||= products
%>
<% if products.empty? %>
 <%= t(:no_products_found) %>
<% elsif params.key?(:keywords) %>
 <h6 class="search-results-title"><%= t(:search_results, :keywords =>  h(params[:keywords])) %></h6>
 <% end %>
 <div class="product_grid_container">
 <div class="grid_2"><%= image_tag("store/featured/#{@featured}.jpg") %></div>
 <% if products.any? %>
  <ul id="products" class="inline product-listing" data-hook>
  <% products.each do |product| %> 
   <% if product.on_display? %>
    <%# ******LIGHTBOX******* %>
     <div id="product_popup_<%= product.id %>" class="product_popup" data-popid="<%= product.id %>">
        <div class="related-products">
          <ul class="related_products_list" id="related_products_list_<%= product.id %>" data-listid="<%= product.id %>">
         <% @related_products.each do |related_product| %>
         <li class="related_products_item"><%= link_to large_image(related_product, :itemprop => "image", :data => {:imageid => related_product.id}, :id => "related_" + related_product.id.to_s, :class => "related_products_image dimmed"), url_for(related_product) %></li>
         <% end %>
    </ul>
        </div>
        <div class="popup-image">
        <%= large_image(product, :itemprop => "image", :class => "product-image-popup") %>
        </div><!-- popup-image -->
        <div class="popup_right_content">
      <h2 class="popup-title"><%= product.name %></h2>
      <p class="popup-price">$<%= product.price %></p>
      <p><%= product.description %></p>
      <p class="popup-color">color:</p>
      <div class="popup-images" data-productid="<%= product.id %>">
            <% if (product.images + product.variant_images).uniq.size > 1 %>
            <ul id="popup-thumbnails-taxon" class="thumbnails inline" data-hook>
            <% product.images.each do |i| %>
                <li class='tmb-all' id='tmb-<%= i.id %>'>
                    <%= link_to(image_tag(i.attachment.url(:small)), i.attachment.url(:popup), :class => 'tmb-all', :id => "tmb-#{i.id}") %>
                </li>
            <% end %>
            </ul>
        <% end %>
    </div><!-- popup-images -->
    </div><!-- popup_right_content -->
        <%= render 'spree/shared/cart_local', :locals => {:product => product} %>
 </div><!-- product_popup -->   
    <%# ******END LIGHTBOX******* %>
  <div class="grid_1">
  <li id="product_<%= product.id %>" class="columns product three <%= cycle("alpha", "secondary", "", "omega secondary", :name => "classes") %>" data-hook="products_list_item" itemscope itemtype="http://schema.org/Product">
    <div class="main-image" id="single_<%= product.id %>" data-productid="<%= product.id %>">

      <%= link_to large_image(product, :itemprop => "image", :class => "product-image", :id => product.id), product_path(product), :remote => true, :html => {:class => "product_popup"}  %>
    </div><!-- main-image-->
    <div class="prod_info_box">
    <%= link_to truncate(product.name, :length => 50), product, :class => 'info', :itemprop => "name", :title => product.name %>
    <span class="price selling" itemprop="price"><%= product.price_in(current_currency).display_price %></span>

    <!-- BRINGS THUMBNAILS INTO TAXONS PAGE -- PULLED FROM _THUMBNAILS.HTML.ERB -->
    <div class="product-images" data-productid="<%= product.id %>">
    <% if (product.images + product.variant_images).uniq.size > 1 %>
        <ul id="product-thumbnails-taxon" class="thumbnails inline" data-hook>
            <% product.images.each do |i| %>
                <li class='tmb-all' id='tmb-<%= i.id %>'>
                    <%= link_to(image_tag(i.attachment.url(:mini)), i.attachment.url(:normal), :class => 'tmb-all', :id => "tmb-#{i.id}") %>
                </li>
            <% end %>
        </ul>
    <% end %>
    </div><!-- product-images -->
    <!-- END THUMBNAILS INTO TAXONS PAGE -->
    <div id="product-description-taxon">
        <p><%= product.description %></p>
    </div><!-- product-description-taxon -->
    </div><!-- prod_info_box -->
  </li>
  </div>
<% end %>
<% end %>

 <% reset_cycle("classes") %>
 </ul>
 <% end %>
 </div><!-- product_grid_container -->
 <% if paginated_products.respond_to?(:num_pages) %>
 <%= paginate paginated_products %>
 <% end %>

需要帮助请叫我。我很感激。

这是帮助者的链接,也许问题在那里? https://github.com/spree/spree/tree/v1.3.2/core/app/helpers/spree

4

1 回答 1

1

在您的_products.html.erb部分更改中:

<%= render 'spree/shared/cart_local', :locals => {:product => product} %>

对此:

<%= render partial: 'spree/shared/cart_local', :locals => {:product => product} %>

并且问题应该得到解决。

为什么?因为按照您的方式执行它不会传递locals到部分,这就是您收到错误的原因,请通过删除locals. 当然,最有趣的部分是为什么你会stack level too deep在这里出错,但我现在无法找到答案。

哦,调试器是你的朋友;)

于 2013-08-26T14:42:08.953 回答