Reputation: 5005
Using tiny_mce from https://github.com/kete/tiny_mce to be able to change the format of the text, the problem is once its submitted it sends the html to my comments and its not getting translated and just outputs to plain html shown below
<ul> <li><span style="text-decoration: underline;"><strong>hello </strong></span></li> <li><span style="text-decoration: underline;">test</span></li> <li><span style="text-decoration: underline;">est</span></li> <li><span style="text-decoration: underline;">est<br /></span></li> </ul>
How do i get rails to translate the html so it displays boldness etc..
I've tried putting it in HTML tags <html><%= comment.body %></html>
which does not work!
Upvotes: 1
Views: 555
Reputation: 106
You should sanitize the input in your model using a before_validation
filter.
I like gem 'sanitize'
, with it you can self.body = Sanitize.clean( self.body, Sanitize::Config::RESTRICTED )
Then you can safely use <%= raw comment.body %>
or <%= comment.body.html_safe %>
to display the HTML.
Upvotes: 0