我开始学习 Ruby on Rails 并创建博客。我已经为博客内容集成了tinyMCE编辑器。但我不知道如何为前端渲染tinyMCE内容。现在它显示的是 html 内容。
内容渲染代码:
%div.container
%h1.text-center Blogs List
= link_to 'New Blog', '/admin/blogs/new', :class => 'btn btn-info'
= link_to 'logout', '/admin/logout' , :class => 'btn btn-info'
%table
%tr
%th.text-center Title
%th.text-center Category
%th.text-center Content
%th.text-center Feature Image
%th.text-center{:colspan => 3} Operations
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1b365b7977747c68357e7a7873" rel="noreferrer noopener nofollow">[email protected]</a> do |blog|
%tr
%td
%h4= blog.title
%td= render blog.categories
%td.mb-4= blog.text #editor content
%td= link_to 'Download', blog.featuredImage_url ,:class=> 'thumbnail'
%td= link_to 'Show', admin_blog_path(blog) , :class=>'btn btn-info'
%td= link_to 'Edit', edit_admin_blog_path(blog), :class=> 'btn btn-info'
%td= link_to 'Destroy', admin_blog_path(blog), :class=> 'btn btn-info', |
method: :delete,
data: { confirm: 'Are you sure?' }
谢谢!!
最佳答案
您可以使用 .sanitize
方法,例如:
%td.mb-4= sanitize(blog.text)
Sanitizes HTML input, stripping all tags and attributes that aren’t whitelisted.
您可以使用(例如)配置白名单标签列表:
# In config/application.rb
config.action_view.sanitized_allowed_tags = ['strong', 'em', 'a']
config.action_view.sanitized_allowed_attributes = ['href', 'title']
关于ruby-on-rails - 如何在haml中渲染tinymce编辑器内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53480759/