Ruby on rails 为什么在RubyonRails 4.2.6中使用simple_格式时会丢失格式?
当我使用html_safe时Ruby on rails 为什么在RubyonRails 4.2.6中使用simple_格式时会丢失格式?,ruby-on-rails,ruby,redactor,Ruby On Rails,Ruby,Redactor,当我使用html_safe时 <%= @micropost.content.html_safe %> 我得到以下格式正确的输出 但当我使用simple_格式时,我失去了中心对齐,并在列表中得到了我不想要的换行符 <%= simple_format(auto_link(@micropost.content, html: { target: '_blank' }), {}, :sanitize => false) %> false)%> 这是我单独使用a
<%= @micropost.content.html_safe %>
我得到以下格式正确的输出
但当我使用simple_格式时,我失去了中心对齐,并在列表中得到了我不想要的换行符
<%= simple_format(auto_link(@micropost.content, html: { target: '_blank' }), {}, :sanitize => false) %>
false)%>
这是我单独使用auto_link和sanitize false时得到的结果
<%= auto_link(@micropost.content, html: { target: '_blank' }, sanitize: false) %>
这是我单独使用auto_link和sanitize true时得到的结果
<%= auto_link(@micropost.content, html: { target: '_blank' }, sanitize: true) %>
这是我在邮报上看到的
>> micp.content
=> "<p style=\"text-align: center;\">Pictre </p><h2 style=\"text-align: center;\">restse</h2><h2>sfsdfsdf</h2><p>sdfdsf</p><p style=\"text-align: center;\">dsfds</p><p>sfsdfsdf</p><ol><li>sdfdsfsdf</li><li>sdfsdfdsf</li><li>sdfdsf</li></ol><div>dfsdfsdfsd</div><p style=\"text-align: center;\">dfsdf</p><ol><li>dsfsdf</li><li>sdf</li><li>sdfsd</li></ol><p style=\"text-align: center;\"><br></p>"
>>
>micp.content
=>“Pictre
RestSesFSDFDFDFsdfdsfdsfds
sfsdfsdfsdfdsfsdf sdfsdfdsf sdfdsf DFSDdfsdf
dsfsdf sdf sdfsd
”
>>
如何解决此问题,并在用户的帖子中设置所需的格式?谢谢。这是api文档:
simple\u format
-返回使用simple
格式化规则。需要两个或多个连续换行符(\n\n)
作为一个段落,用
标签包装。一个换行符(\n)是
视为换行符,并附加
标记。这种方法
不从文本中删除换行符
因此,不是:
<%= simple_format(auto_link(@micropost.content, html: { target: '_blank' }), {}, :sanitize => false) %>
false)%>
您可能应该执行以下操作:
<%= auto_link(@micropost.content, html: { target: '_blank' }, sanitize: false) %>
有关更多信息,请参阅和。这来自api文档:
simple\u format
-返回使用simple
格式化规则。需要两个或多个连续换行符(\n\n)
作为一个段落,用
标签包装。一个换行符(\n)是
视为换行符,并附加
标记。这种方法
不从文本中删除换行符
因此,不是:
<%= simple_format(auto_link(@micropost.content, html: { target: '_blank' }), {}, :sanitize => false) %>
false)%>
您可能应该执行以下操作:
<%= auto_link(@micropost.content, html: { target: '_blank' }, sanitize: false) %>
有关更多信息,请参阅和。我尝试了您的解决方案,但只得到html标记。我已更新了问题中的输出。请尝试使用
sanitize:true
我现在获得了输出,但仍然丢失了格式。我尝试了您的解决方案,但只获得了html标记。我已更新了问题中的输出。请尝试使用sanitize:true
我现在获得了输出,但仍然丢失了格式。