Skip to content

Instantly share code, notes, and snippets.

@NeoElit
Last active April 7, 2016 06:59
Show Gist options
  • Save NeoElit/d1fe81aa60e7d61247f80e2ebdbf0358 to your computer and use it in GitHub Desktop.
Save NeoElit/d1fe81aa60e7d61247f80e2ebdbf0358 to your computer and use it in GitHub Desktop.
class BlogPostScrubber < Rails::Html::PermitScrubber
def allowed_node?(node)
%w(div p video strong em a blockquote h3 h4 h5 h6 br hr i label li span u ul ol).include?(node.name)
end
def skip_node?(node)
node.text?
end
def scrub_attribute?(name)
name == "style"
end
end
#body data
@blog_post.body = "<p>Hello <strong>bruce</strong>,</p>\r\n\r\n<p><img alt=\"\" src=\"https://upload.wikimedia.org/wikipedia/commons/b/b6/1896_Olympic_opening_ceremony.jpg\" style=\"height:150px; width:192px\" /></p>\r\n"
<p>Hello <strong>bruce</strong>,</p>
<p><img src="https://upload.wikimedia.org/wikipedia/commons/b/b6/1896_Olympic_opening_ceremony.jpg" style="height: 150px; width: 192px;"></p>
#view code
<p id="notice"><%= notice %></p>
<p>
<strong>Title:</strong>
<%= @blog_post.title %>
</p>
<p>
<strong>Body:</strong>
<div id="mydiv">
<%= sanitize @blog_post.body, scrubber: BlogPostScrubber.new %>
</div>
</p>
<%= link_to 'Edit', edit_blog_post_path(@blog_post) %> |
<%= link_to 'Back', blog_posts_path %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment