2014-04-02 61 views
0

看来,我不由自主地将请求发送到Shopify API从我的观点:429错误在我的轨道查看,但我不知道在哪里,我将请求发送到Shopify的API

ActionView::Template::Error (Failed. Response code = 429. Response message = Too Many Requests.): 

340:    myProducts.desc.push(description.substring(6, description.length-6) +' <br>'+ 
338: 
342:    '<p style=\"float:right;color:#c1c1c1;\"><a href=<%="https://#{shop_session.url}/products/#{product.handle}"%> target=\"_blank\">View in Shopify</a></p>'); 
343:    myProducts.img.push('<%= product.images.first.medium %>'); 
341:    '<p><i><%= product.price_range %> <%= shop_session.shop.currency %></i></p>'+ 
344:   } 
app/views/home/index.html.erb:341:in `block in  _app_views_home_index_html_erb__4367043927235243173_45266480' 
app/views/home/index.html.erb:328:in `each' 
app/views/home/index.html.erb:328:in `each_with_index' 

代码产生误差

<% @products.each_with_index do |product, index| %> 
     var escapedTitle = '<%= JSON.generate(raw(product.title), quirks_mode: true) %>'; 
     escapedTitle = escapedTitle.substring(6, escapedTitle.length-6); 
     //console.log("COMPARE " + selectedProducts[i] + " WITH: " + escapedTitle); 
     if (selectedProducts[i]== escapedTitle) { 
     myProducts.title.push(selectedProducts[i]); 

     //console.log("MATCH!"); 

     var description = '<%= JSON.generate(raw(product.body_html), quirks_mode: true) %>'; 

     myProducts.desc.push(description.substring(6, description.length-6) +' <br>'+ 
      '<p><i><%= product.price_range %> <%= shop_session.shop.currency %></i></p>'+ 
      '<p style=\"float:right;color:#c1c1c1;\"><a href=<%="https://#{shop_session.url}/products/#{product.handle}"%> target=\"_blank\">View in Shopify</a></p>'); 
     myProducts.img.push('<%= product.images.first.medium %>'); 
     } 
    <% end %> 

更具体地,误差线328产生:

<% @products.each_with_index do |product, index| %> 

共ntroller该视图正在发送下面的请求

@products = ShopifyAPI::Product.find(:all, :params => {:limit => 250}) 

为什么我的观点显然派遣更多的请求,要求产品?我如何正确地做到这一点?

该错误类似于this one,但在这种情况下,他们正在请求原始请求中未包含(或未包含)产品的元字段。但我直接与产品合作,而不是特别的。

回答

0

我发现这个问题是

myProducts.desc.push(description.substring(6, description.length-6) +' <br>'+ 
     '<p><i><%= product.price_range %> <%= shop_session.shop.currency %></i></p>'+ 
     '<p style=\"float:right;color:#c1c1c1;\"><a href=<%="https://#{shop_session.url}/products/#{product.handle}"%> target=\"_blank\">View in Shopify</a></p>'); 

更具体地说,

<%= shop_session.shop.currency %> 

这是从送我认为所有的请求的一部分。所以,我说

@shop = ShopifyAPI::Shop.current 

到我的控制器和改变了代码

<%= @shop.currency %> 

问题解决了。

相关问题