【发布时间】:2020-04-23 04:29:04
【问题描述】:
我正在尝试将stored_products 从shopify 传递到Rails 应用程序,但在https://f588240c.ngrok.io/ 处不断收到家庭控制器错误我已经进行了更新,但没有成功,并且多次重新启动服务器,但没有成功。
欢迎任何帮助。这是代码
class Api::V1::HomeController < ShopifyApp::AuthenticatedController
def index
@products = ShopifyAPI::Product.find(:all, params: { limit: 10 })
@products.each do |product|
StoredProduct.where(shopify_id: product.id)
.first_or_create do |stored_product|
stored_product.shopify_id = product.id
stored_product.shopify_title = product.title
stored_product.shopify_handle = product.handle
stored_product.shopify_image_url = product.image.src
stored_product.shop_id = @shop.id
stored_product.save
product.images.each do |image|
ProductImage.where(shopify_id: image.id)
.first_or_create do |product_image|
product_image.image_url = image.src
product_image.stored_product_id = stored_product_id
product_image.shopify_id = image.id
end
end
end
end
@stored_products = StoredProduct.belongs_to_shop(@shop.id)
end
end
来自经过身份验证的控制器
private
def set_shop
@shop = Shop.find_by(id: session[:shopify])
set_locale
end
来自 store_products.rb 文件
class StoredProduct < ApplicationRecord
belongs_to :shop
has_many :product_images
scope :belongs_to_shop, -> shop_id { where(shop_id: shop_id) }
end
【问题讨论】:
标签: ruby-on-rails ruby shopify-app