I recently made a small rails3 app to convert an old cms written in another language. After migrating the content I am having problems outputting content from the database.
The @content.desc field sometimes has html. Currently the only way I could get it to work was:
<%= sanitize content.desc %>
But is this the best way? When I use <%=h @content.desc %> I can see the html tags still. When I use <%= simple_format @content.desc %> I get wicked spacing.
Is there a definitive guide somewhere where I can see all of the options while outputting content? I’ve tried to search but can’t turn anything up (rails newb, i know).
Any string not marked as “safe” will be HTML-escaped by default in Rails 3. Some methods, such as
sanitize,h,link_toand many other helpers return safe strings, thus allowing them to be written literally. See this blog post for more info.If you know for sure that the HTML contained in
@content.descis safe, you can mark it as such yourself like so:<%= @content.desc.html_safe %>.