我正在将应用程序从Rails 2升级到Rails 3.显然,render()现在调用返回ActionView::OutputBuffer而不是String.我需要将结果传递render()给URI.escape(),这会失败,但异常......
ob = ActionView::OutputBuffer.new("test test")
URI.escape(ob)
`NoMethodError: undefined method 'each_byte' for nil:NilClass`.
from /opt/ruby19/lib/ruby/1.9.1/uri/common.rb:307:in `block in escape'
from ..../ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/core_ext/string/output_safety.rb:160:in `gsub'
from ..../ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/core_ext/string/output_safety.rb:160:in `gsub'
from /opt/ruby19/lib/ruby/1.9.1/uri/common.rb:304:in `escape'
from /opt/ruby19/lib/ruby/1.9.1/uri/common.rb:623:in `escape'
Run Code Online (Sandbox Code Playgroud)
而且,在OutputBuffer上调用to_s会返回相同的OutputBuffer类,所以我甚至无法将此缓冲区转换为诚实的字符串?
ob.to_s.class
ActionView::OutputBuffer
Run Code Online (Sandbox Code Playgroud)
当然,调用URI.escape("test test")会按预期返回"test%20test",因此这不是URI问题.
环境:
我的问题是:为什么会发生这种情况,我该如何解决这个问题呢?
更新:显然,使用'' + ob作为一种ob.to_s将OutputBuffer转换为String 的形式,它可以有效地解决问题...但我的问题' 为什么会发生这种情况 '仍然存在,例如这是一个错误,我应该报告,还是我做错了什么?