如何在 haml 中呈现 tinymce 编辑器内容?

how to render tinymce editor content in haml?

我在 rails 上开始学习 ruby 并创建博客。我已经为博客内容集成了 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
      -@blogs.each 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']

.sanitize method doc