【发布时间】:2020-10-29 15:44:59
【问题描述】:
我正在创建一个 Shopify 应用,我想将图像与商店模型一起附加。
但是当我添加与商店模型的活动存储关联时,我无法开始服务。
错误
/home/web/.rvm/gems/ruby-2.6.1/gems/activerecord-6.0.1/lib/active_record/dynamic_matchers.rb:22:in
method_missing': undefined methodhas_one_attached' for Shop(调用'Shop. connection' 建立连接):Class (NoMethodError)
配置:
rails:- 6.0.1,ruby:- 2.6.1,shopify_app:- 11.3.2
这就是我的代码现在的样子
shop.rb
class Shop < ActiveRecord::Base
include ShopifyApp::SessionStorage
has_one_attached :icon, dependent: :destroy
end
config/initializers/shopify_app.rb
ShopifyApp.configure do |config|
config.application_name = "App Name"
config.api_key = ENV['shopify_api_key']
config.secret = ENV['shopify_api_secret']
config.old_secret = "<old_secret>"
config.scope = "write_script_tags,read_script_tags,read_themes"
config.embedded_app = false
config.after_authenticate_job = false
config.api_version = ShopifyVersion.shopify_api_version
config.session_repository = Shop
config.webhooks = [
{topic: 'app/uninstalled', address: 'https://example.com/webhooks/app_uninstalled', format: 'json'},
{topic: 'shop/update', address: 'https://example.com/webhooks/shop_update', format: 'json'},
end
我试过这个: config/initializers/shopify_app.rb
config.session_repository = 'ShopifyApp::InMemorySessionStore'
但是,它仍然无法用于生产。
错误
ShopifyApp::InMemorySessionStore::EnvironmentError(无法在生产环境中使用 InMemorySessionStore。请使用可以存储和检索会话的模型初始化 ShopifyApp):
另外,尝试升级 gem 版本但没有希望,然后使用当前配置创建一个演示,它会工作。我不明白为什么它不适用于我当前的项目。
谁能给我解释一下?
非常感谢您的建议。 抱歉英语不好。
提前致谢。
【问题讨论】:
标签: ruby-on-rails rails-activestorage shopify-app