【问题标题】:I can't get a vanilla Rails + Turbolinks Shopify App working我无法使用普通 Rails + Turbolinks Shopify 应用程序
【发布时间】:2023-08-22 23:54:02
【问题描述】:

我刚刚浏览了Rails & Turbolinks tutorial - 因为我是第一次创建 Shopify 应用。我到了我的应用程序正在加载的阶段,但我看到的只是“正在加载...”页面,它是“SplashPage#Index”,但它没有像我预期的那样重定向到我的“Home#Index”。

我正在使用Rails 6.0.3.6Ruby 3.0.1,但我没有使用 React。如果可能的话,我只想使用 Rails 和 Turbolinks 来构建我的应用程序,这就是我选择该教程的原因。

这是服务器日志(注意,出于隐私目的,我将 IP 地址设为空白)。

Started GET "/?hmac=5e2e8c366d75e39831b775be635e4118a99c&host=bWFueS1wcmXlzaG9waWZ5LmNvbS9hZG1pbg&locale=en&new_design_language=true&session=7deccadd83c28b82dd4dd2902fff5c76573f365f637c2a&shop=random-shop.myshopify.com&timestamp=1619310003" for 69.160.XXX.XX at 2021-04-24 19:20:04 -0500

┃ Cannot render console from 69.160.XXX.XX! Allowed networks: 127.0.0.0/127.255.255.255, ::1

┃ Processing by SplashPageController#index as HTML

┃   Parameters: {"hmac"=>"5e2e8c366d75e39831b775be635e4118a99c", "host"=>"bWFueS1wcmXlzaG9waWZ5LmNvbS9hZG1pbg", "locale"=>"en", "new_design_language"=>"true", "session"=>"7deccadd83c28b82dd4dd2902fff5c76573f365f637c2a", "shop"=>"random-shop.myshopify.com", "timestamp"=>"1619310003"}

┃   Shop Load (1.8ms)  SELECT "shops".* FROM "shops" WHERE "shops"."shopify_domain" = $1 LIMIT $2  [["shopify_domain", "random-shop.myshopify.com"], ["LIMIT", 1]]

┃   CACHE Shop Load (0.2ms)  SELECT "shops".* FROM "shops" WHERE "shops"."shopify_domain" = $1 LIMIT $2  [["shopify_domain", "random-shop.myshopify.com"], ["LIMIT", 1]]

┃   Rendering splash_page/index.html.erb within layouts/embedded_app

┃   Rendered splash_page/index.html.erb within layouts/embedded_app (Duration: 0.1ms | Allocations: 6)

┃ [Webpacker] Everything's up-to-date. Nothing to do

┃   Rendered layouts/_flash_messages.html.erb (Duration: 0.6ms | Allocations: 76)

┃ Completed 200 OK in 38ms (Views: 24.5ms | ActiveRecord: 2.3ms | Allocations: 8450)

什么可能导致这种行为,我该如何解决?

您还需要查看哪些其他代码来帮助我正确解决此问题?

编辑 1

不确定这是否与任何事情有关,但从我的rails console,当我做ShopifyApp.configuration.api_key 时,我得到nil 返回。

编辑 2

当我检查我的 JS 控制台时,我看到以下错误:

Uncaught Error: Cannot find module '@shopify/app-bridge-utils'

但在我的app/javascript/packs/application.js 中,我包含了以下内容:

require("shopify_app")

编辑 3

这是来自 JS 控制台的完整错误:

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-6 turbolinks shopify-app


    【解决方案1】:

    我终于明白了。即使我没有明确使用 NPM,我仍然需要将 @shopify/app-bridge 实用程序包含到我的 JS 包管道中。

    我通过运行以下命令来做到这一点:

    $ yarn add @shopify/app-bridge
    $ yarn add @shopify/app-bridge-utils
    

    效果很好,现在一切顺利。

    【讨论】: