The h method is still suitable for removing all HTML inside a string. This method should be used wherever you display content.
<%=h @recipe.description %>
This behavior will change in Rails 3. There, all output will be escaped by default, and you will need to explicitly specify so as not to avoid this. At the same time, if you often forget to use this h method, you can check the secure ERB plugin .
The sanitize method is a good way to selectively select specific tags from content. For example, if you want to allow the user to bold and italicize their output along with adding links, you can do this.
<%= sanitize @recipe.description, :tags => %w[bia], :attributes => %w[href] %>
As Oliver said, check out the Security Guide for more information.
ryanb
source share