I have an erb template in which I need to use:
CGI.unescapeHTML(someEscapedHTML)
So I need to require 'cgi', however the following fails:
<% require 'cgi' %>
With the error:
can't dup NilClass
I would personally never put a require statement in a view, because 1) it's ugly and 2) what if another view needed that require?
A better place for this is in config/application.rb
at the bottom, or in a file in config/initializers
.
First of all do not require gems or libraries in ERB please. Then CGI is required by Rails itself already.
If you want to prevent Rails 3 from auto-escaping consider using
<%= data.html_safe %>
instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With