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

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控制台调用时,它工作正常,但是当从controller调用时,我得到:
 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

你们能帮帮我吗…提前谢谢

最佳答案

您可以在“taxcloud::address”上使用“::taxcloud::address”位置

07-24 13:34