Hey all, this is a pretty simple question but I can''t seem to find anything on the wikki or google... Is there a Ruby/Rails equivilent to PHP''s nl2br function? -- Posted via http://www.ruby-forum.com/.
simple_format("whatever\n\n") =>
"whatever<br/><br/>"
found in TextHelper
On 4/13/06, hieg <hieg@visioncritical.com> wrote:>
> Hey all, this is a pretty simple question but I can''t seem to find
> anything on the wikki or google... Is there a Ruby/Rails equivilent to
> PHP''s nl2br function?
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060413/41638222/attachment.html
Try some_string.gsub!(/\n/, ''<br />'') You also might want to look at Textile (http://www.textism.com/tools/textile/index.php) or Markdown -----Original Message----- From: rails-bounces@lists.rubyonrails.org [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of hieg Sent: Thursday, April 13, 2006 7:17 AM To: rails@lists.rubyonrails.org Subject: [Rails] equivilent to PHP''s nl2br? Hey all, this is a pretty simple question but I can''t seem to find anything on the wikki or google... Is there a Ruby/Rails equivilent to PHP''s nl2br function? -- Posted via http://www.ruby-forum.com/. _______________________________________________ Rails mailing list Rails@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails
Awsomr, thanks to both of you! -- Posted via http://www.ruby-forum.com/.
I wrote a helper function:
def nl2br(string)
string.gsub("\n\r","<br>").gsub("\r",
"").gsub("\n", "<br />")
end
This seems to work fairly well. I put it in the application helper
wherever I think I''ll need it. I feed it html, say like this: nl2br(h
(@object.text))
You could certainly modify it so that it automatically wraps the
input in an h().
Nicholas P. Mueller
On Apr 13, 2006, at 12:16 PM, hieg wrote:
> Hey all, this is a pretty simple question but I can''t seem to find
> anything on the wikki or google... Is there a Ruby/Rails
> equivilent to
> PHP''s nl2br function?
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails