简体   繁体   English

在Rails视图上出现429错误,但我不知道我在哪里向Shopify的API发送请求

[英]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.

相关问题 Rails 功能规范:调用了外部 Google 字体 API,但我不知道在哪里 - Rails feature specs: external Google font API is called, but I don't know where 在rails中,我正在发送一个var以查看,但是在js文件中为nil - in rails I'm sending a var to view and but in js file is nil 为什么我得到这个`ActiveRecord :: RecordNotFound。 (找不到&#39;id&#39;)`我的Rails API中的POST请求出错? - Why am I getting this `ActiveRecord::RecordNotFound. (Couldn't find 'id') ` error from POST requests in my Rails API? Heroku无法正常工作,我不知道从哪里开始 - Heroku not working and I don't know where to start PG::ForeignKeyViolation: ERROR: update or delete on table 我不知道为什么 - PG::ForeignKeyViolation: ERROR: update or delete on table and I don't know why in my case 我的Heroku应用崩溃了(错误H10),我不知道为什么 - My Heroku app is crashing (error H10) and I don't know why 不会让我运行rails,因为有另一台服务器正在运行,但是我不知道如何访问该服务器 - wont let me run rails s because there is another server running but i don't know how to access that server 我的图片正在上传,但似乎无处可见(它根本没有显示) - 不知道我哪里出错了 - My image is uploading, but to nowhere it seems (it's not showing at all) - haven't a clue where I'm going wrong Rails应用程序加载错误,无法使用“ rais s”命令启动应用程序,而是出现了错误 - Rails app Load Error, Couldn't start the app with 'rais s' command, instead I'm getting error 从我的Rails表单中,我收到404错误。 有人知道如何正确设置此AJAX表单吗? - From my Rails form, I'm getting a 404 Error. Anyone know how to properly set up this AJAX form?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM