26

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?

1 Answer 1

43

ERB::Util.html_escape

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.