I have in my erb file something like this:
<%= simple_format(...) %>
The generated code is wrapped within <p></p>. In my case, I need the code be interpolated without this wrapping. Can this be done?
Ronald
I have in my erb file something like this:
<%= simple_format(...) %>
The generated code is wrapped within <p></p>. In my case, I need the code be interpolated without this wrapping. Can this be done?
Ronald
This is an effect of using the simple_format method: http://api.rubyonrails.org/classes/ActionView/Helpers/TextHelper.html#method-i-simple_format
"Returns text
transformed into HTML using simple formatting rules. Two or more consecutive newlines(\n\n
) are considered as a paragraph and wrapped in <p>
tags. One newline (\n
) is considered as a linebreak and a <br />
tag is appended. This method does not remove the newlines from the text
.
You can pass any HTML attributes into html_options
. These will be added to all created paragraphs."
If you just want to print out the bare text, you can just put that in your erb tag: <%= my_variable %>
If you just want to print out the bare text, you can just put that in your erb tag: <%= my_variable %>
This didn't work either, because the value of my_variable contains simple quotes, and these had been replaced by an HTML entity denotation (in this case, it is '). That's why I thought I would need simple_format (I was not aware that the <p> was coming from simple_format .... I should have known this)
Maybe I post here my code in question:
<% js_unhide_idstrings=@sequence[1..-1].map {|n| "'tu_idiom_#{n}'"} %> <script> ... var unhide_ids=[<%= js_unhide_idstrings.join(',') %>]; ... </script>
If @sequence is, say [4,1,9], the generated JavaScript code would be
var unhide_ids=['tu_idiom_1','tu_idiom_9'];
if you change js_unhide_idstrings.join(‘,’) to js_unhide_idstrings.join(‘,’).html_safe that should decode the entities.
Thanks a lot, this is the solution I was looking for!