-
-
Save NeoElit/d1fe81aa60e7d61247f80e2ebdbf0358 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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