Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 4: html_safe for only specific tags

I want to allow a couple specific tags like (<br>) but let rails continue to escape others. Html_safe does not appear to take any arguments. What's the smoothest way to do this?

like image 554
emersonthis Avatar asked Sep 18 '13 14:09

emersonthis


Video Answer


1 Answers

The sanitize helper will html encode all tags and strip all attributes that aren’t specifically allowed.

sanitize @article.body, :tags => %w(br)

Link to API Docs.

like image 118
zwippie Avatar answered Oct 11 '22 01:10

zwippie