0

I am using ckeditor to save posts content. If I save anything in my db then it saves content with html tags. To escape html i am using <%= raw(posts.content) %> function. I am using Speak.js for adding functionality to listen posts content also. Here i am doing like this ...

<script src="speakClient.js"></script>
<img src="img/listenpost.png" alt="Listen Post" onclick="speak('<%= posts_item.content.html_safe %>')" style="cursor:pointer;" />

but here it speaks content with html tags. I tried to do like this also

 speak('<%== posts_item.content %>') or  speak('<%= raw posts_item.content %>')

But nothing works for me. How can I escape html tags so that my posts audible without HTML tags

4

2 回答 2

2

您也应该在 javascript 中转义。使用escape_javascript助手

speak('<%=j posts_item.content.html_safe %>')
于 2013-05-24T07:00:14.273 回答
0

你说你已经试过了speak('<%= raw posts_item.content %>')。在这种情况下,原始辅助方法的正确使用是<%= raw(posts_item.content) %>(注意posts_item.content在括号内

于 2013-05-24T06:58:37.873 回答