Can't use raw after truncate rails

耗尽温柔 提交于 2020-01-02 23:14:12

问题


The trouble is if I use <% @description = (truncate(post.content, :separator => '[---MORE---]', :length => 0))%> and then I try to print it - <%= raw @description %> I still see all html tags.


回答1:


truncate escapes the string by default, but you can turn it off using :escape option:

@description = (truncate(post.content, :separator => '[---MORE---]', :length => 0, :escape => false))

Other approach would be to mark the post.content as html safe:

truncate(post.content.html_safe, ...

If you do this you can even remove the raw.



来源:https://stackoverflow.com/questions/20937600/cant-use-raw-after-truncate-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!