未初始化的常量User :: TaxCloud

时间:2015-09-24 18:56:30

标签: ruby-on-rails ruby

我将税云与我的应用程序集成以计算销售税。当我试图从控制台运行税云时,它运行良好。见下文

irb(main):002:0> u = User.last
irb(main):006:0> u.calculate_sales_tax
7.0

用户模型中的方法。

def calculate_sales_tax
  origin = TaxCloud::Address.new(
      :city => 'xxxx',
      :state => 'NJ',
      :zip5 => '08106')
  destination = TaxCloud::Address.new(
      :city => 'xxxxx',
      :state => "#{self.state}",
      :zip5 => "#{self.zip_code}")
  transaction = TaxCloud::Transaction.new(
      :customer_id => "#{self.id}",
      :origin => origin,
      :destination => destination)
  transaction.cart_items << TaxCloud::CartItem.new(
      :index => 0,
      :item_id => 'xxxx',
      :tic => TaxCloud::TaxCodes::PREWRITTEN_COMPUTER_SOFTWARE_DELIVERED_ELECTRONICALLY,
      :price => 100.00,
      :quantity => 1)
  lookup = transaction.lookup   # this will return a TaxCloud::Responses::Lookup instance
  puts lookup.tax_amount        # total tax amount
end

当我从rails控制台调用时工作正常,但是当调用来自控制器时,我得到了:

 NameError (uninitialized constant User::TaxCloud)

控制器:

class SubscriptionsController < ApplicationController
  load_and_authorize_resource :user
  load_and_authorize_resource :through => :user

  def index
    @sales_tax = @user.calculate_sales_tax
  end
end

你们可以帮助我......提前致谢

1 个答案:

答案 0 :(得分:0)

您可以在“TaxCloud :: Address”

上使用“:: TaxCloud :: Address”