Index: branches/locker-dev/locker/deploy/bin/rails
===================================================================
--- branches/locker-dev/locker/deploy/bin/rails	(revision 2124)
+++ branches/locker-dev/locker/deploy/bin/rails	(revision 2149)
@@ -5,4 +5,5 @@
 use onserver;
 use Tie::File;
+use Cwd;
 
 setup();
@@ -38,5 +39,9 @@
 my $prod_db = make_db("production");
 
-system qw{rails new . -D -d mysql };
+my $cwd = getcwd;
+system("rails", "new", $cwd ,"-d", "mysql");
+my $appdir = `basename $cwd`;
+chomp $appdir;
+my $appclass = ucfirst $appdir;
 
 open PUBLIC_HTACCESS, ">public/.htaccess";
@@ -120,13 +125,37 @@
 untie @railsfcgi;
 open RAILSFCGI, ">>public/dispatch.fcgi";
+print RAILSFCGI "#!/usr/bin/ruby\n";
 print RAILSFCGI <<EOF;
+require File.join(File.dirname(__FILE__), '../config/environment')       
+require 'rack'
 
 ## Added by scripts.mit.edu autoinstaller to reload when app code changes
 Thread.abort_on_exception = true
 
+class Rack::PathInfoRewriter
+  def initialize(app)
+    \@app = app
+  end
+
+  def call(env)
+    env["SCRIPT_NAME"] = ""
+    parts = env['REQUEST_URI'].split('?')
+    env['PATH_INFO'] = parts[0]
+    env['QUERY_STRING'] = parts[1].to_s
+    \@app.call(env)
+  end
+end
+
+
 t1 = Thread.new do
-   RailsFCGIHandler.process!
+  dispatch_logger = Logger.new(File.join(Rails.root,'log/dispatcher.log'))
+
+  begin
+    Rack::Handler::FastCGI.run Rack::PathInfoRewriter.new(Rack::URLMap.new("/$appdir" => ${appclass}::Application))
+  rescue => e
+   dispatch_logger.error(e)
+   raise e
+  end
 end
-
 t2 = Thread.new do
    # List of directories to watch for changes before reload.
@@ -195,4 +224,10 @@
 ## End of scripts.mit.edu autoinstaller additions
 EOF
+chmod 0755,'public/dispatch.fcgi';
+
+# have to explicitly take a dependency on fcgi
+open GEMFILE, ">>Gemfile";
+print GEMFILE "gem 'fcgi'\n";
+close GEMFILE;
 
 print "Your application is located in:\n";
