简体   繁体   English

Rails activestorage 不适用于 shopify_app gem

[英]Rails activestorage not working with shopify_app gem

I am creating a Shopify app, I want to attach the image with the shop model.我正在创建一个 Shopify 应用程序,我想将图像与商店 model 一起附加。

but I can not able to start to serve when I add active storage association with the shop model.但是当我添加与商店 model 的活动存储关联时,我无法开始服务。

error错误

/home/web/.rvm/gems/ruby-2.6.1/gems/activerecord-6.0.1/lib/active_record/dynamic_matchers.rb:22:in method_missing': undefined method has_one_attached' for Shop (call 'Shop.connection' to establish a connection):Class (NoMethodError) /home/web/.rvm/gems/ruby-2.6.1/gems/activerecord-6.0.1/lib/active_record/dynamic_matchers.rb:22:in method_missing': undefined method has_one_attached(调用'Shop.connection ' 建立连接):Class (NoMethodError)

configuration:配置:

rails:- 6.0.1 , ruby:- 2.6.1 , shopify_app:- 11.3.2导轨:- 6.0.1 ,ruby:- 2.6.1 ,shopify_app:- 11.3.2

This is what my code looks like now这就是我的代码现在的样子

shop.rb商店.rb

class Shop < ActiveRecord::Base
  include ShopifyApp::SessionStorage

  has_one_attached :icon, dependent: :destroy
end

config/initializers/shopify_app.rb配置/初始化程序/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

I tried this: config/initializers/shopify_app.rb我试过这个:config/initializers/shopify_app.rb

config.session_repository = 'ShopifyApp::InMemorySessionStore'

but still, it's not working on the production.但是,它仍然无法进行生产。

error错误

ShopifyApp::InMemorySessionStore::EnvironmentError (Cannot use InMemorySessionStore in a Production environment. Please initialize ShopifyApp with a model that can store and retrieve sessions): ShopifyApp::InMemorySessionStore::EnvironmentError(不能在生产环境中使用 InMemorySessionStore。请使用可以存储和检索会话的 model 初始化 ShopifyApp):

also, try to upgrade the gem version but no hope then create a demo with the current configuration and it will work.另外,尝试升级 gem 版本但没有希望,然后使用当前配置创建一个演示,它将起作用。 I can not understand why it will not work on my current project.我不明白为什么它不适用于我当前的项目。

can anyone explain it to me?谁能给我解释一下?

I really appreciate your suggestions.我真的很感谢你的建议。 sorry for bad English.抱歉英语不好。

Thanks in advance.提前致谢。

After doing google and try to search on the Shopify community.在做谷歌并尝试在 Shopify 社区上搜索。 i got some suggestions, and base on suggestion i try to update only the shopify_app gem version and configuration base on the new version.我得到了一些建议,根据建议,我尝试仅更新 shopify_app gem 版本和基于新版本的配置。

It works for me.这个对我有用。

change 13.2.0 instead of 11.3.2 .更改13.2.0而不是11.3.2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM