Text field formatting

17 views
Skip to first unread message

Dave Castellano

unread,
Sep 11, 2013, 8:04:36 AM9/11/13
to rubyonra...@googlegroups.com
Hi,

I am trying to figure out how to convert line breaks to html line
breaks ie <br>

The text is imput and saved as:
Which structures traverse above the annulus of Zinn?
A) Lacrimal nerve
B) Frontal nerve
C) Nasociliary nerve
D) CN IV
E) CN III

but, I have a text field in my show action view with the following:
<%= "#{@formatted_question[:question]}" %>

which produces:
Which structures traverse above the annulus of Zinn? A) Lacrimal nerve
B) Frontal nerve C) Nasociliary nerve D) CN IV E) CN III

The line breaks are still there, they just aren't being converted to
HTML line breaks. I can see them when I view the source.

How can I get the line breaks back??

Thanks,
Dave

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

Dave Castellano

unread,
Sep 11, 2013, 8:41:11 AM9/11/13
to rubyonra...@googlegroups.com
Got it! simple_format(text)

jsnark

unread,
Sep 11, 2013, 8:46:16 AM9/11/13
to rubyonra...@googlegroups.com

<%= "#{@formatted_question[:question].gsub(/\n/, '<br/>')}" %>

jsnark

unread,
Sep 11, 2013, 9:01:56 AM9/11/13
to rubyonra...@googlegroups.com
Oops.

<%= "#{@formatted_question[:question].gsub(/\n/, '<br/>').html_safe}" %>
Reply all
Reply to author
Forward
0 new messages