Rails WYSIWYG显示代码而不是样式内容

时间:2018-05-02 11:57:40

标签: ruby-on-rails wysiwyg froala

预期的行为。 描述由froala在show action中设计。

实际行为。 actual behavior

重现问题的步骤。 我使用rails代码_form,所以我无法在jsfiddle中运行它 - 请允许我在下面的代码中添加它。

_form.html.erb

align-items: center;

show.html.erb

 <script> $(function() { $('textarea').froalaEditor() }); </script>
<div class="section">
<%= simple_form_for @post do |f| %>
  <div class="field">
    <div class="control">
      <%= f.input :title, input_html: { class: 'input' }, wrapper: false, label_html: { class: 'label' } %>
    </div>
  </div>    
  <div class="field">
    <div class="control">
      <%= f.input :content, input_html: { class: 'textarea' }, wrapper: false, label_html: { class: 'label' }  %>
    </div>
  </div>    
  <div>
   <%= f.label :image %>
   <%= f.file_field :image %>
 </div>    
  <%= f.button :submit, 'Create new post', class: "button is-primary" %>
<% end %>
</div>

的application.js

<% content_for :page_title, @post.title %>
<link href="../css/froala_style.min.css" rel="stylesheet" type="text/css" />
<section class="section" style="margin: auto;">
  <div class="container">
      <% if current_user.try(:editor) %>
    <nav class="level">
      <div class="level-left">
        <p class="level-item">
          <strong>admin</strong>
        </p>
      </div>
      <div class="level-right">
        <p class="level-item">
          <%= link_to "edytuj", edit_post_path(@post), class:"button"%>
        </p>
        <p class="level-item">
          <%= link_to "skasuj", post_path(@post), method: :delete, data: {confirm: "Are you sure?"}, class: "button-is-danger"%>
        </p>
      </div>
    </nav>
    <% end %>
    <hr />
  <p class="title is-2"><%=  @post.title %></p>
    <%= image_tag(@post.image.url, alt: 'Image') if @post.image? %>
      <div class="fr-view">
      <%= @post.content %>
</div>
    </div>
  </div>
</section>
<section class="section comments">
    <div class="container">
        <h2 class="subtitle is-5"><strong><%= @post.comments.count %></strong> Comments</h2>
        <%= render @post.comments %>
        <div class="comment-form">
            <hr />
            <h3 class="subtitle is-3">Leave a reply</h3>
            <%= render 'comments/form' %>
        </div>
    </div>
</section>

application.scss.erb

// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's
// vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file. JavaScript code in this file should be added after the last require_* statement.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require rails-ujs
//= require turbolinks
//= require_tree .
//= require froala_editor.min.js    
#= require plugins/align.min.js
#= require plugins/char_counter.min.js
#= require plugins/code_beautifier.min.js
#= require plugins/code_view.min.js
#= require plugins/colors.min.js
#= require plugins/emoticons.min.js
#= require plugins/entities.min.js
#= require plugins/file.min.js
#= require plugins/font_family.min.js
#= require plugins/font_size.min.js
#= require plugins/fullscreen.min.js
#= require plugins/help.min.js
#= require plugins/image.min.js
#= require plugins/image_manager.min.js
#= require plugins/inline_style.min.js
#= require plugins/line_breaker.min.js
#= require plugins/link.min.js
#= require plugins/lists.min.js
#= require plugins/paragraph_format.min.js
#= require plugins/paragraph_style.min.js
#= require plugins/print.min.js
#= require plugins/quick_insert.min.js
#= require plugins/quote.min.js
#= require plugins/save.min.js
#= require plugins/table.min.js
#= require plugins/special_characters.min.js
#= require plugins/url.min.js
#= require plugins/video.min.js

OS: Linux Ubuntu 17.10

浏览器: 铬65.0.3325.181

1 个答案:

答案 0 :(得分:0)

您可以使用h()方法转义html内容

<%=h @post.content %>