Created
November 16, 2011 09:29
-
-
Save oshow/1369670 to your computer and use it in GitHub Desktop.
for Rubyist Magazine 0036
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
require 'rubygems' | |
require 'sinatra/base' | |
require 'sinatra/reloader' | |
require 'rack/rewrite' | |
require 'haml' | |
class App < Sinatra::Base | |
enable :inline_templates | |
enable :logging | |
configure :development do | |
set :server, "webrick" | |
register Sinatra::Reloader | |
end | |
use Rack::Rewrite do | |
rewrite %r{^/song_for/(.*)}, '/name/$1' | |
end | |
get '/' do | |
@title = "Top" | |
haml "My Way" | |
end | |
get '/name/:name' do | |
@name = params[:name] | |
@title = "Song for #{@name}" | |
haml "#{@name}'s Way" | |
end | |
end | |
App.run! | |
__END__ | |
@@ layout | |
!!! 5 | |
%html | |
%head | |
%title= @title | |
%body | |
%h1= @title | |
%div= yield |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment