简体   繁体   中英

ActiveShipping and Grape (Rails) - uninitialized constant API::V1::Shippings::ActiveShipping

I use Grape to create an API in rails. Now I want to use Shopify's Active Shipping gem but when I try to use this in my custom_helper within Grape I get a uninitialized constant ActiveShipping error message. In addition I also get the following message:

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">]

my helper file looks like:

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

and I include it in my grape shippings file like:

module API
  module V1
    class Shippings < Grape::API
        helpers API::V1::Helpers::ShippingHelpers 
       ...
        #some endpoint:
          ups_tracking_info(tracking_info)
       ...
    end
  end
end

Why do I get the uninitialized constant error message? I do require the gem in my helper file.. requireing it in my config/application.rb file doesn't work either...

Hope someone will have an idea, that can help me further. Thanks in Advance!

Note I have all my grape files in app/api/api folder so that is not the problem..

Turned out the documentation with the gem on github is incorrect. The correct information is written here . I had to include ActiveMerchant::Shipping in my class and drop the use of ActiveMerchant::Shipping within the code. So use UPS.new() or FedEx.new() etc. instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM