Showing posts with label textarea in view page. Show all posts
Showing posts with label textarea in view page. Show all posts

Monday, March 2, 2009

Line breaks in textarea in Ruby

Well it is very simple although i spent a lot of time on this but I got the solution which is very simple.


<%= (@object.details).gsub("\n","\
") %>

note:'do not use \ in your code that i used here \
, just simply use break tag'

what I was doing is

<%=h (@object.details).gsub("\n","\
") %>

the last line I mentioned here is using a <%=h which is generated by scaffold. So dont use this <%=h, simply use <%= and gsub method and it will work fine.

Note: using <%=h ... %> ensures that any HTML contained within would not render directly into the page, but instead convert <>