Is it possible to require a class in an erb template?

I have an erb template in which I need to use:

CGI.unescapeHTML (someEscapedHTML)

Therefore, I need to require "cgi", however the following fails:

<% require 'cgi' %>

With an error:

cannot duplicate nilclass

+5
source share
2 answers

First of all, you do not need stones or libraries in ERB. Then CGI requires Rails itself.

If you want to prevent Rails 3 from being automatically shielded, use

<%= data.html_safe %>

instead.

+3
source

I personally would never put a require query in a view because 1) it is ugly and 2) what if another view is required that requires?

config/application.rb config/initializers.

+5

All Articles