Rails で API を作成するためにGrapeを使用しています。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 フォルダーにあることに注意してください。これは問題ではありません。