UPS Shipping Gem not working - Fixed

Hello everyone,

I recently had the joy of working with the Ruby Shipping gem which allows you to grab shipping rates from UPS and FEDEX. However many people (myself included) have had problems with this gem. The reason is simple the documentation contains misinformation and is causing many developers to bang there heads. I found a solution and would like to share, so here it is.

OK first off make your life easier and create a file
/config/shipping.yml and add your ups account information as shown
below.

#in your config/shipping.yml file
ups_license_number: ups_xml_access_key
ups_user: ups_username
ups_password: ups_password

One important thing to notice is that I am using ups_license_number: as
opposed to ups_account: as shown in the Shipping gem docs :( . This is
what is causing all the trouble. Also note that I am using the xml
access key and not the account number.

Next you need a method to get your quote. Here is a quick one to get you
started.

#in your controller
def ups_quote(to_zip, sender_zip, weight)
  #define the parameters for the quote
  params ={
  :zip => to_zip,
  :sender_zip => sender_zip,
  :weight => weight,
  :prefs => "#{RAILS_ROOT}/config/shipping.yml"
  }
  #build the shipping gem object
  @shipping = Shipping::UPS.new params
end

#in your view

Shipping Quote: <%= number_to_currency @shipping.price %>

Leave a Reply