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

Free-Minded
  • 5,322
  • 6
  • 50
  • 93
  • `speak('<%== posts_item.content %>')` - There should be only one equal sign after the `%` (`<%=`) –  May 24 '13 at 06:55
  • `speak('<%== posts_item.content %>')` or `speak('<%= raw posts_item.content %>')` both works same – Free-Minded May 24 '13 at 06:58
  • My mistake. I'm used to only putting down one equal sign –  May 24 '13 at 06:59

2 Answers2

2

You should escape also inside javascript. Using escape_javascript helper

speak('<%=j posts_item.content.html_safe %>')
ck3g
  • 5,829
  • 3
  • 32
  • 52
0

You state that you have tried speak('<%= raw posts_item.content %>'). The correct use of the raw helper method in this case would be <%= raw(posts_item.content) %> (note that posts_item.content is inside parentheses