gpt4 book ai didi

javascript - 格式化文本未呈现并在 View 中显示为代码

转载 作者:行者123 更新时间:2023-11-29 17:20:22 24 4
gpt4 key购买 nike

我正在使用 bootstrap-wysihtml5 gem ,一个所见即所得的表单文本编辑器,适用于我的应用程序。当我在我的文本区域中输入如下所示的内容时:

“这是一个测试,看看粗体斜体是否有效”

我在我看来是这样的:

"this is a test to see if **bold** and *italic* are working"

任何 html 都显示为代码,而不是呈现为格式化文本。似乎格式正在编码,只是没有正确呈现。是什么原因造成的?

我的代码如下,紧跟自述文件。

posts/_form.html.erb

<%= form_for @post, :html => { :multipart => true } do |f| %>

<%= f.label :content %>
<%= f.text_area :content, :class => 'wysihtml5' %>

<%= f.label :photo %>
<%= f.file_field :photo %>

<script type="text/javascript">
$('.wysihtml5').each(function(i, elem) {
$(elem).wysihtml5();
});
</script>

<div class="actions">
<%= f.submit %>
</div>

<% end %>

posts/_post.html.erb

<div class="photo"><%= image_tag post.photo.url %></div>
<div class="content"><%= post.content %></div>

最佳答案

posts/_post.html.erb 中试试这个

<div class="content"><%= post.content.try(:html_safe) %></div>

关于javascript - 格式化文本未呈现并在 View 中显示为代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13383417/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com