Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy URI.escape fails when called on ActionView::OutputBuffer?
    primarykey
    data
    text
    <p>I'm upgrading an application from Rails 2 to Rails 3. Apparently, calling <code>render()</code> now returns <code>ActionView::OutputBuffer</code> and not <code>String</code>. I need to pass the results of <code>render()</code> to <code>URI.escape()</code>, and this fails with exception...</p> <h3>Here is my brief testing in the console</h3> <pre><code>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' </code></pre> <p>Moreover, calling to_s on OutputBuffer returns same OutputBuffer class, so I cannot even convert this buffer into a honest string?</p> <pre><code>ob.to_s.class ActionView::OutputBuffer </code></pre> <p>Of course, calling URI.escape("test test") returns "test%20test" as expected, so this is not URI problem.</p> <p>Environment: </p> <ul> <li>ruby 1.9.3p125 (2012-02-16 revision 34643) [i686-linux]</li> <li>Rails 3.2.1</li> </ul> <p>My question is: <strong>Why does this happen and how can I work around this issue?</strong></p> <p><strong>Update:</strong> Apparently, using <code>'' + ob</code> as a form of <code>ob.to_s</code> converts OutputBuffer to String, which effectively works around the problem... But my question '<em>why does this happen</em>' still remains, e.g. is this a bug, should I report it, or I'm doing something wrong?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload