[英]429 error on my rails view but I don't know where I'm sending requests to Shopify's API
It seems that I'm involuntarily sending requests to the Shopify API from my view: 从我看来,我似乎是在不自觉地向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'
The code that produces the error is 产生错误的代码是
<% @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 %>
More specifically, the error is produced on line 328: 更具体地说,该错误是在第328行产生的:
<% @products.each_with_index do |product, index| %>
The controller for that view is sending the following request 该视图的控制器正在发送以下请求
@products = ShopifyAPI::Product.find(:all, :params => {:limit => 250})
Why is my view apparently sending more requests asking for products? 为什么我的观点显然会发送更多要求产品的请求? How can I do it properly?
我该怎么做呢?
The error is similar to this one but in that case they were requesting for metafields, which are (or were) not included in the original request for products. 该错误是类似于这一个 ,但在这种情况下,他们请求metafields,这是(或曾经是)不包括在产品的原始请求。 But I'm directly working with the products, not with anything special.
但是我直接使用产品,而不使用任何特殊的东西。
I found out that the problem was 我发现问题是
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>');
More specifically, the part with 更具体地说,
<%= shop_session.shop.currency %>
This was sending all the requests from my view. 这是我发送的所有请求。 So, I added
所以,我加了
@shop = ShopifyAPI::Shop.current
to my controller and changed that code for 到我的控制器并更改了该代码
<%= @shop.currency %>
Problem solved. 问题解决了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.