ruby-on-rails - 在不同的 Controller 中使用 Shopify API

标签 ruby-on-rails sqlite model-view-controller shopify

我需要获取当前商店的域(我使用 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/

相关文章:

asp.net-mvc - MVC 中用于灵活调查的正确模型

php - 使用 Zend Framework 2 扩展 ZfcUser

ios - 在 iOS 中将通知从模型发送到 Controller

ruby-on-rails - Rails 原始发布源代码

ruby-on-rails - 在 Rails 4 中保存之前如何检查现有记录?

ruby-on-rails - 无法在 Mac OS X 10.5.8 (Leopard) 上安装 sqlite3 gem

c# - SQLite & C# ] 如何控制编辑数据库文件的人数?

javascript - FixedHeader 的问题

ruby-on-rails - 在 cancan、ability.rb 中使用范围

android - 零星的 NullPointerException 尽管对象不为空