Posts Tagged ‘rack’

Hello Rack

Posted 15 Dec 2009 — by admin
Category ruby

What is Rack?

Rack provides a minimal, modular and adaptable interface for developing web applications in Ruby. By wrapping HTTP requests and responses in the simplest way possible, it unifies and distills the API for web servers, web frameworks, and software in between (the so-called middleware) into a single method call.

- Rack API Docs


Create and name your file config.ru If rack isn’t installed get it with this command

gem install rack

In your config.ru file

require 'rubygems'
require 'rack'

class HelloRack
  def call(env)
    [200, {"Content-Type" => "text/html"}, "Hello Rack!"]
  end
end

Rack::Handler::Mongrel.run HelloRack.new, :P ort => 8888

Check out http://m.onkey.org/2008/11/17/ruby-on-rack-1

Deploy Sintra App on Ubuntu Using Apache2 and Phusion Passenger Module

Posted 12 Aug 2009 — by admin
Category Sinatra

Check it out http://sinatra.seanbehan.com/
This assumes Apache2 and the Phusion Passenger module have already been installed. If not you can get up to speed w/ this resource http://seanbehan.com/ruby-on-rails/new-ubuntu-slice-apache-mysql-php-ruby-on-rails-git-and/

First you need Sinatra, so install the gem

gem install sinatra

We need a home for Frank, so create the minimum number of directories in our web directory. The public directory is where we’ll server images, stylesheets, javascript etc. The tmp directory will be where we control Passenger.

cd /var/www/sinatra
mkdir myapp
mkdir myapp/tmp
mkdir myapp/public

cd myapp
vim index.rb
#in index.rb
get '/' do
  "Fly me to the moon..."
end

Next we need a configuration file for Rack, important the file extension is “.ru” not .rb!

vim config.ru
require 'rubygems'
require 'sinatra'

Sinatra::Application.default_options.merge!(
  :run => false,
  :env => ENV['RACK_ENV']
)

require 'index'
run Sinatra.application

Set up the virtual host


  ServerName www.myapp.com
  DocumentRoot /var/www/sinatra/public

Now you can restart the app if you make adjustments!

touch tmp/restart.txt

Keep on singing :)

Inspired by http://blog.zerosum.org/2008/7/4/passenger-3-sinatra