Can I do <%=.%> interpolation without getting a <p> tag?

34 views
Skip to first unread message

Ronald Fischer

unread,
Jul 7, 2014, 5:31:31 AM7/7/14
to rubyonra...@googlegroups.com
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

--
Posted via http://www.ruby-forum.com/.

James Turley

unread,
Jul 7, 2014, 5:37:41 AM7/7/14
to rubyonra...@googlegroups.com
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 %>



--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/d57a3149f8a9e5c413b84db959c5e6f4%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

Ronald Fischer

unread,
Jul 7, 2014, 5:51:33 AM7/7/14
to rubyonra...@googlegroups.com
> 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 &#39;). 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=[&#39;tu_idiom_1&#39;,&#39;tu_idiom_9&#39;];

James Turley

unread,
Jul 7, 2014, 6:29:16 AM7/7/14
to rubyonra...@googlegroups.com
if you change js_unhide_idstrings.join(',') to js_unhide_idstrings.join(',').html_safe that should decode the entities.


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.

Ronald Fischer

unread,
Jul 7, 2014, 7:44:02 AM7/7/14
to rubyonra...@googlegroups.com
Thanks a lot, this is the solution I was looking for!
Reply all
Reply to author
Forward
0 new messages