Active Merchant-未初始化的常量ActiveSupport :: XmlMini_REXML :: StringIO [英] Active Merchant - uninitialized constant ActiveSupport::XmlMini_REXML::StringIO

查看:120
本文介绍了Active Merchant-未初始化的常量ActiveSupport :: XmlMini_REXML :: StringIO的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有现役商人1.16.0和rails 3.0.5。

I have activemerchant 1.16.0 and rails 3.0.5.

我正在尝试构建基本代码,以便使用现役商人与PayPal网关进行通信。

I am trying to build a basic code to communicate with PayPal's gateway using active merchant.

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()调用传播。
您知道我的设置有什么问题吗?
谢谢。

This error propagates from the gateway.authorize() call. Any idea what's wrong with my setup? Thanks.

推荐答案

安德鲁·格里姆(Andrew Grimm)对这个问题的最初评论几乎使人震惊。缺少要求'stringio'的确是问题所在。但这是Rails的一个错误,更具体地说是ActiveSupport 3.0.9(这似乎是错误的出处)。我们可以使用rails的git commit历史记录对其进行跟踪。

Andrew Grimm pretty much hit the nail on the head with his original comment on this question. The missing require 'stringio' is indeed the issue. But it is a bug with Rails, more specifically ActiveSupport 3.0.9 (which is where the error seems to be coming from). We can trace it down using the git commit history of rails.

首先,我们需要检查rails并切换到v3.0.9标签。现在,如果我们查看 activesupport / lib / active_support / xml_mini / rexml.rb ,我们会看到需要'stringio'是不在那里。就其本身而言,这并不重要,但请耐心等待。现在,我们可以切换到下一个标记(v3.0.10.rc1),我们会看到文件尚未更新(此版本的rails可能会出现相同的问题)。该行中的下一个标记是v3.1.0.beta1,请注意,这一次在文件顶部有一个要求'stringio'

First we need to check out rails and switch to the v3.0.9 tag. If we now look at activesupport/lib/active_support/xml_mini/rexml.rb we see that require 'stringio' is not there. In and of itself this is not significant, but bear with me. We can now switch to the next tag (v3.0.10.rc1), and we'll see that the file hasn't been updated (it is likely that this version of rails will have the same issue). Next tag in line is v3.1.0.beta1, notice that this time around there is a require 'stringio' at the top of the file.

我们可以检查出导致此更改的提交(此处是一个从2011年1月19日开始)。提交消息说:

We can check out the commit that brought in this change (this one here from Jan 19th 2011). The commit message says:


解决了在
non-rails env中使用AS时会导致麻烦的缺失要求的情况。 >

fixed a missing require that causes trouble when using AS in a non-rails env

这表示只要您处于铁路环境中,这个问题就不会出现。因此,我的猜测是有关导致问题出现的环境问题,可能与OP表示他们正在使用rails 3.0.5 有关,但该错误来自activesupport - 3.0.9 。也许是从一个rake任务中调用了该代码,该任务忘记了从:environment 继承(很难说,没有更多信息)。无论哪种方式,在代码顶部放置 require'stringio'绝对是解决方法,直到可以升级到Rails 3.1(一旦出现),这时不再需要。

This would indicate that as long as you're in a rails environment this issue wouldn't surface. So, my guess is something about the environment caused the issue to come up, may have something to do with the fact that the OP says they are using rails 3.0.5, but the error is coming from activesupport-3.0.9. Perhaps the code was called from a rake task that forgot to inherit from :environment (difficult to say without more info). Either way, putting require 'stringio' at the top of the code is definitely the fix, until you can upgrade to Rails 3.1 (once it comes out) at which point the require will no longer be needed.

这篇关于Active Merchant-未初始化的常量ActiveSupport :: XmlMini_REXML :: StringIO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆