ruby-on-rails - 如何在haml中渲染tinymce编辑器内容?

标签 ruby-on-rails ruby tinymce haml

我开始学习 Ruby on Rails 并创建博客。我已经为博客内容集成了tinyMCE编辑器。但我不知道如何为前端渲染tinyMCE内容。现在它显示的是 html 内容。 enter image description here

内容渲染代码:

%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']

.sanitize method doc

关于ruby-on-rails - 如何在haml中渲染tinymce编辑器内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53480759/

相关文章:

php - 调整 Tinymce 大小

jquery - 通过 jquery 加载的 TinyMCE 错误

ruby-on-rails - 将 JSON 数据作为 post 方法从 Rails Controller 发送到 Web 服务

ruby-on-rails - Ruby:Declarative_authorization 多态关联

ruby-on-rails - 如何检测给定文本的语言

ruby-on-rails - Rails 4 Heroku 部署错误 : Precompiling assets failed - cannot import/find boostrap file

ruby - 没有表格的 Rails 模型

ruby-on-rails - Rails 对象在当前返回 false?但是 !nil 是真的吗?

ruby - Discourse 安装 - 安装必要的 gems 会报错

TinyMCE 去掉 p 标签中的 br 标签