我使用Grape在 Rails 中创建 API。现在我想使用 Shopify 的Active Shipping gem,但是当我尝试在 Grape 中的 custom_helper 中使用它时,我收到一条uninitialized constant ActiveShipping
错误消息。此外,我还收到以下消息:
Cannot render console with content type application/jsonAllowed content types: [#<Mime::Type:0x007f8bea21b4e8 @synonyms=["application/xhtml+xml"], @symbol=:html, @string="text/html">, #<Mime::Type:0x007f8bea21b038 @synonyms=[], @symbol=:text, @string="text/plain">, #<Mime::Type:0x007f8bec0fe950 @synonyms=[], @symbol=:url_encoded_form, @string="application/x-www-form-urlencoded">]
我的帮助文件如下所示:
require 'active_shipping'
module API
module V1
module Helpers
module ShippingHelpers
extend Grape::API::Helpers
def ups_tracking_info(tracking_number)
ups = ActiveShipping::UPS.new(login, password, key) #this is where it throws an error
ups.find_tracking_info(tracking_number)
end
end
end
end
end
我将它包含在我的葡萄运输文件中,例如:
module API
module V1
class Shippings < Grape::API
helpers API::V1::Helpers::ShippingHelpers
...
#some endpoint:
ups_tracking_info(tracking_info)
...
end
end
end
为什么我会收到未初始化的常量错误消息?我确实需要我的帮助文件中的 gem.. 在我的 config/application.rb 文件中需要它也不起作用......
希望有人有一个想法,可以进一步帮助我。提前致谢!
注意我的所有葡萄文件都在 app/api/api 文件夹中,所以这不是问题..