Call for help! Ruby - On - Rails Shipping Gem
Hello everyone, I have been programming in Ruby using the Rails framework for a while now. However I have a situation where I am developing a shipping calculator for my applications using the Ruby “shipping gem”. The problem, at least I think, is the account number, username, password or all of the aforementioned attributes are incorrect. I have verified they are indeed correct and valid. I am getting an object returned to me in my code called the Shipping::ShippingError object. I am sure there is some kind of a message stored inside this object but I cannot access it because I think it is actually a Class. In short what I need to know is how do I, if at all extract the error from this Class? Object? so I can display it to the screen. Below is a code example.
The configuration file “shipping.yml”
#../../config/shipping.yml ups_account: XXXXX ups_user: XXXXX ups_password: XXXXX
The Shipping Controller “app/controllers/shipping_controller.rb”
#app/controllers/shipping_controller.rb
class ShippingController < ApplicationController
def quote
params = {
:zip => 54494,
:state => “Wisconsin”,
:weight => 1,
:sender_zip => 68801,
:sender_state = “Nebraska”,
:prefs => “#{RAILS_ROOT}/config/shipping.yml” }
@shipping = Shipping::UPS.new params
@errors = Shipping::ShippingError
#in the view we will show price like so @shipping.price
end
end
The view file “shipping/quote.rhtml”
Test Shipping This is a test of the UPS shipping code.Output = [<%= @shipping.price %>]
Leave a Comment