MVC with ruby-web

You can get MVC action by combining two features of ruby-web. Before loading a page, ruby-web looks up the directory tree for an "application.rb" file. Then, in the application.rb file, you can define a Web::filter [1].

Let's use a basic hello.world.rb as an example:

#!/usr/bin/env ruby-web
puts "Hello World"

When you visit this cgi script, you'll get "Hello World". If you add this application.rb in the same directory as hello.world.rb:

Web::filter do |content|
"<h1>#{content}</h1>"
end

Visit the script again, and notice that Hello World is a bit louder. You can also have multiple chained filters:

Web::filter do |content|
"<h1>#{content}</h1>"
end

Web::filter do |content|
content.gsub(/Hello World/, "Hallo Welt")
end

Take that, Servlet API!


A few notes:

1. If you are running ruby-web 1.0.0, Web::ob_start is a more cryptic name for the exact same function. If you are running php, ob_start is also your friend :-)

2. I'm sorry that ruby-web scripts still run as basic cgi scripts. Alas, I have not yet written enough SAPI modules. One day I'll get them all done.


A New Hope

This site was dedicated to the NARF web libraries. These have been moved to http://www.ruby-web.org. From now on, NARF will be dedicated to an attitude towards projects. That what Ruby needs isn't big ideas, but problem solving code.

In other words, this site will be dedicated to the attitude that generated ruby-web and raainstall. I will celebrate the can do, pragmattic, software engineering mentality that has made projects like Perl and PHP so friendly.

I will continue to post updates on the status of ruby-web, but I will also feature useful projects like the Nullsoft Installer System, Docbook, and whatever else is friendly and productive.

I hope to follow the example of these great projects. Cue the fanfare, courtesy of http://www.frazmtn.com/~punstr/midi/.



~ Patrick May