我需要获取当前商店的域(我使用 ShopifyAPI::Shop.current.domain
来执行此操作)。这在 HomeController 中有效,可以在 home/index.html.erb
中显示。 .但是,当我尝试调用 ShopifyAPI::Shop.current.domain
在我的 CustomController 中显示在不同的 View 中,我收到错误 Missing site URI
.
我认为这是因为一旦用户离开主页/索引 View ,它就不再有权访问该 Shop 实例。那么,如果我不知道 id,如何在我的 CustomController 中重新创建该实例。例如,这有效:
@shop = Shop.find(1)
@domain = @shop.shopify_domain
但是,我不会总是知道商店的
id
在模型中。或者,也许我以错误的方式接近这个。
最佳答案
迟到但使用 around_filter :shopify_session
在你的 Controller 中应该解决这个问题。如果不是,请确保 Controller 继承自 AuthenticatedController
.
例子:
class CustomerController < AuthenticatedController
around_filter :shopify_session
def shops
@shop = ShopifyAPI::Shop.find(1)
end
end
关于ruby-on-rails - 在不同的 Controller 中使用 Shopify API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32147181/