开发者

Showing linebreaks in Rails3

I 开发者_JAVA技巧store the linebreaks as "line\n\nline" in the database.

When i am displaying it, I convert it using this method:

  def showLineBreaks(from_textarea) 
   from_textarea.gsub(/\n/,"<br/>")
  end

But these renders the text as

line<br><br>line 

instead of showing the linebreaks.

What is the right way to do this?


You probably need to flag your content as html_safe for it to display properly, otherwise the view will render it as the string should be displayed.

<%= showLineBreaks.html_safe %>


If you're trying to display newlines saved from text areas, you could do the following in your view:

<%= simple_format from_textarea %>

No need to do manual substitution in this case.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜