2014-04-02 65 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 %> 

問題解決了。

相關問題