Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I escape HTML in a Rails 3.1 controller method?

h / html_escape don’t work within a controller method.

I know, it’s for views. (Or was — haven’t done much Rails since v2.3). But I’m just building an eensy-weensy string and want to use this method in my controller.

So how can I escape HTML from within a controller method?

like image 953
Alan H. Avatar asked Jul 13 '11 23:07

Alan H.


1 Answers

ERB::Util.html_escape

You can include ERB::Util in your controller to use these methods directly.

like image 64
Michaël Witrant Avatar answered Sep 21 '22 13:09

Michaël Witrant