活跃商家 - 未初始化常量 ActiveSupport::XmlMini_REXML::StringIO

2024-01-09

我有 activemerchant 1.16.0 和 Rails 3.0.5。

我正在尝试构建一个基本代码来使用活跃商家与 PayPal 网关进行通信。

if credit_card.valid?
  # or gateway.purchase to do both authorize and capture
  response = gateway.authorize(1000, credit_card, :ip => "127.0.0.1")
  if response.success?
    gateway.capture(1000, response.authorization)
    puts "Purchase complete!"
  else
    puts "Error: #{response.message}"
  end
else
  puts "Error: credit card is not valid. #{credit_card.errors.full_messages.join('. ')}"
end

我收到以下错误:

/Library/Ruby/Gems/1.8/gems/activesupport-3.0.9/lib/active_support/xml_mini/rexml.rb:20:in `parse': uninitialized constant ActiveSupport::XmlMini_REXML::StringIO (NameError)

此错误从gateway.authorize()称呼。 知道我的设置有什么问题吗? 谢谢。


根据问题,当代码本身时它不起作用,但当require "stringio"被添加。

我怀疑 ActiveMerchant 是经过单元测试的,但由于某种原因,这些单元测试没有检测到对 StringIO 的依赖,可能是因为单元测试代码的其他部分间接requires stringio。

我最近发现的一件事是require 'yaml'为您提供 stringio 库作为副作用:

StringIO.new
# NameError: uninitialized constant StringIO
#   from (irb):1
require "yaml"
# => true
StringIO.new
# => #<StringIO:0x7fb7d48ce360>
RUBY_VERSION
# => "1.8.7"

不难想象 ActiveMerchant(或 Rails 的其他部分)的单元测试需要 yaml。

然而,这只是猜测。我没有检查过,因为我不使用 Rails。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

活跃商家 - 未初始化常量 ActiveSupport::XmlMini_REXML::StringIO 的相关文章

随机推荐