PHP ob_start in Ruby

I need to include Content-Length in each file. In PHP it would be:

<?php ob_start(); ?>

html

<?php header('Content-Length: ' . ob_get_length()); ob_end_flush(); ?>

How can I do the same in Ruby?

Thanks,
eduard

I think there should be a “how to do equivalent PHP function in Ruby”
page on the Wiki…

eduard wrote:

?>


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


I do things for love or money

+44 (0)7941 219 501

aim:oulalipo | yahoo:tachekent

Dorian M. wrote:

I think there should be a “how to do equivalent PHP function in Ruby”
page on the Wiki…

I’ve started Peak Obsession.
The idea is that each page in the PHP manual should have an equivalent
in the Rails Wiki, and each PHP function should have a page either
showing the way you do it in Ruby/Rails, or a short explanation as to
why it’s not necessary. I made a quick start to the main menu and the
date/time functions to show what could be done… Good idea? Bad? If
people like it, I’ll try to keep up with filling it, but it’d be good to
have a few others at it, too.

In your Application Controller, add this:

after_filter { |controller|
controller.response.headers[‘Content-Length’] =
controller.response.body.length

}


From: [email protected]
[mailto:[email protected]] On Behalf Of eduard
Sent: Thursday, January 19, 2006 9:40 AM
To: [email protected]
Subject: [Rails] PHP ob_start in Ruby

I need to include Content-Length in each file. In PHP it would be:

<?php ob_start(); ?>

html

<?php header('Content-Length: ' . ob_get_length()); ob_end_flush(); ?>

How can I do the same in Ruby?

Thanks,
eduard

Thanks Tom, it works great!