【问题标题】:Completed 500 Internal Server Error and ActiveResource::ForbiddenAccess已完成 500 内部服务器错误和 ActiveResource::ForbiddenAccess
【发布时间】:2019-03-29 09:27:38
【问题描述】:

我正在使用 Shopify、Ruby on Rails 和 Heroku postgres,但我不断收到此错误:

ActiveResource::ForbiddenAccess (Failed. Response code = 403. Response message = Forbidden.) and Completed 500 Internal Server Error in 210ms (ActiveRecord: 1.3ms)

我正在尝试将 Shopify 的数据 CRUD 到另一个来自 rails 的应用程序,我尝试迁移数据库和 heroku 日志以找出问题,但我没有找到。

这是我的控制器代码

def index
  @products = ShopifyAPI::Product.find(:all, params: { limit: 10 })
  @webhooks = ShopifyAPI::Webhook.find(:all)
end

def show
  @products = ShopifyAPI::Product.find(params[:id])
end

def new
  @products = ShopifyAPI::Product.new
end

def create
  @products = ShopifyAPI::Product.new(params.require(:product).permit(:title))
  if @products.save
    redirect_to home_index
  else
    render :index
  end 
end

这是我的路线

Rails.application.routes.draw do
  resources :home
  post 'home/new', to: 'home#create'
end

我的 new.html.erd

<%= form_for :product do |f| %>
  <p> 
    <%= f.label :name %>
    <%= f.text_field :title %>
  </p> 

  <p>
    <%= f.submit %>
  </p>
<% end %>

这是我的 index.html.erd

<% @products.each do |product| %>
  <li><%= link_to product.title, "https://#{@shop_session.url}/admin/products/#{product.id}", target: "_top" %></li>
  <%= link_to 'Create Product', new_home_path %>     
<% end %>

【问题讨论】:

  • 你有什么问题?
  • 请分享您的错误屏幕截图以找出问题。
  • HTTP 500 是一般的服务器端错误消息。它本身几乎没有告诉我们任何事情。每当您看到这一点时,您的第一步应该是检查您的错误日志以获取更多详细信息。以heroku logs开头。

标签: ruby-on-rails ruby heroku ruby-on-rails-5 shopify


【解决方案1】:

简单。您正在调用 API 并且您未经过身份验证,因此您返回 403。您需要首先打开经过身份验证的会话,然后调用 API。例如:

session = ShopifyAPI::Session.new(shop, token)
ShopifyAPI::Base.activate_session(session) if session.valid?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-22
    • 2015-02-23
    • 1970-01-01
    • 2021-06-09
    • 2011-11-27
    • 2016-02-13
    • 2013-06-02
    • 2019-01-17
    相关资源
    最近更新 更多