我试图向我的 shopify 应用程序添加经常性费用。我遵循Shopify-Tutorial但写的略有不同。我的根路线去:
root 'mycontroller#charging'
控制器动作是:
def charging
if @shop_domain != @myshop
@shop_charging_status = @shop.charging
unless ShopifyAPI::RecurringApplicationCharge.current
recurring_charge = ShopifyAPI::RecurringApplicationCharge.new(
name: "My App",
price: "1.99",
return_url: "https:\/\/appurl\/activated",
trial_days: 7,
terms: "$1.99 per month")
if recurring_charge.save
@tokens[:confirmation_url] = recurring_charge.confirmation_url
@shop_charging_status = true
@shop.save
redirect recurring_charge.confirmation_url
end
end
else
redirect_to myindex_path
end
当我尝试启动应用程序时,我收到一个错误:NoMethodError(未定义的方法 `[]=' for nil:NilClass)。它涉及@token 行。当我写代码的时候,这一行已经让我很困惑了,因为变量@token 只用在这个方法中。但是,为什么它是零?
我错过了什么?