gpt4 book ai didi

ruby-on-rails - Solidus 运费计算器错误

转载 作者:太空宇宙 更新时间:2023-11-03 16:14:28 25 4
gpt4 key购买 nike

我正在自定义我的 Solidus 项目以访问 Correios 的 API(Correios 是巴西的邮件和投递)来计算运费,但发生错误。

我正在使用 gem 'correios-frete'。当我在命令行中运行一个 ruby​​ 文件(correios.rb listen bellow)时没有问题。

# correios.rb
require 'correios-frete'
require 'pry-byebug'

frete = Correios::Frete::Calculador.new :cep_origem => "22790-671",
:cep_destino => "06783-090",
:peso => 7.3,
:comprimento => 30,
:largura => 20,
:altura => 35

servicos = frete.calcular :sedex, :pac

binding.pry
puts servicos

但是当我在项目的正确文件中插入集成行时:

# app/models/spree/calculator/shipping/correios_api.rb

# frozen_string_literal: true

# require 'correios-frete'
require_dependency 'spree/calculator'
require_dependency 'spree/shipping_calculator'

module Spree
module Calculator::Shipping
class CorreiosApi < ShippingCalculator
preference :api_key, :string

def compute_package(_package)
binding.pry
calcula

9090.90
end

def self.description
"Correios API"
end


def calcula
binding.pry
frete = Correios::Frete::Calculador.new :cep_origem => "22790-671",
:cep_destino => "06783-090",
:peso => 7.3,
:comprimento => 30,
:largura => 20,
:altura => 35

servicos = frete.calcular :sedex, :pac
binding.pry
end
end
end
end

引发此错误:

NameError - uninitialized constant Spree::Calculator::Shipping::CorreiosApi::Correios:
app/models/spree/calculator/shipping/correios_api.rb:26:in `calcula'
app/models/spree/calculator/shipping/correios_api.rb:14:in `compute_package'

此错误在下面一行出现:

frete = Correios::Frete::Calculador.new :cep_origem => "22790-671",
:cep_destino => "06783-090",
:peso => 7.3,
:comprimento => 30,
:largura => 20,
:altura => 35

最佳答案

白痴问题...我安装了 gem 但是,我没有重启 rails server :-o

关于ruby-on-rails - Solidus 运费计算器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50431678/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com