Single file Rails Application
Published almost 7 years ago

UPDATE 1 : The inspiration for this article came from here ( it predates yo mama ). It has abso-fucking-lutely nothing to do with merb whatsoever. And “fuck you to your face” is NOT directed towards anything/anyone :)

Just for fun and profit

require 'rubygems'
require 'thin'
require "action_controller"
require 'dispatcher'

# Rails pwned
ActionController::Base.session = { :session_key => "_myapp_session", :secret => "some secret phrase of at least 30 characters" }
ActionController::Routing.use_controllers! ['home']
ActionController::Dispatcher.unprepared = false
Dependencies.mechanism = :require

class ActionController::Dispatcher
  def prepare_application
  end
end

# And your routes
ActionController::Routing::Routes.draw do |map|
  map.root :controller => 'home'
  map.connect ':controller/:action/:id'
end

# Application code
class ::HomeController < ActionController::Base
  def index
    render :text => "fuck you to your face"
  end
  
  def hello
    render :text => params.inspect
  end
end

# Make Thin Happy
class LifoAdapter
  def call(env)
    rack_response = Rack::Response.new
    rack_request = Rack::Request.new(env)    
    cgi = Rack::Adapter::Rails::CGIWrapper.new(rack_request, rack_response)
    ActionController::Dispatcher.dispatch(cgi, ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS, rack_response)    
    rack_response.finish
  end
end

# Run LifoAdapter
Thin::Server.start('0.0.0.0', 3000) do
  use Rack::CommonLogger
  run LifoAdapter.new
end

UPDATE 2

I just made a few more changes for funkification, which you can find at my github repository

With tinyrails, the “hello world” application looks like :

# thin -p 3000 -r mini.rb start

require 'tinyrails'

routes { root :controller => 'home' }

controller "home" do
  def index
    render :text => "Hello World"
  end
end

start

You can also use models/views with tinyrails, as demonstrated here

UPDATE 3 : Fabiano França changed the code to run it with webrick/mongrel. He also has a funky microrest framework. His pastie can be found here