"Content-type" => "text/html" }, "Hello world."] end end run RackApp.new $ rackup --env development => INFO WEBrick::HTTPServer#start: pid=37743 port=9292 $ curl http://localhost:9292/ => Hello world.
params["captures"] => [annee] end get %r{^(\d{4})/(\d{2})$} do |annee, mois| "Les articles du mois #{mois} de #{annee}" # params["captures"] => [annee, mois] end # seulement ruby 1.9 get %r{^(?<annee>\d{4})/(?<mois>\d{2})$} do "Les articles du mois #{params[:mois]} de #{params[:annee]}" end
authenticate! end get "/admin/dashboard" do "Tableau de bord de quelqu’un d’authentifié" end post "/admin/billets" do "Création d’un billet par quelqu’un d’authentifié" end
do sass :screen # /views/screen.sass end get "/api/articles.xml" do builder :"api/articles"# /views/api/articles.builder end get "/api/articles.json" do coffee :"api/articles" # /views/api/articles.coffee end
start --env production >> Thin web server (v1.2.8 codename Black Keys) >> Listening on 0.0.0.0:3000, CTRL+C to stop $ rackup --env development => INFO WEBrick::HTTPServer#start: pid=37743 port=9292 $ rackup --env production => INFO WEBrick::HTTPServer#start: pid=37743 port=9292
:key => "efg456" } end configure :production do set :s3, { :bucket => "blogue", :key => "abc123" } end get "/" do "La valeur de s3/bucket est de #{settings.s3[:bucket]}" end
être <a href=\"/login\">connecté</a>." end end get "/login" do haml :login end post "/login" do if params[:username] == "foo" and params[:password] == "bar" session[:admin] = true redirect "/admin" end end
include Rack::Test::Methods def app; Blogue; end def test_redirection_mauvais_acces_au_tableau_de_bord get "/admin/dashboard" assert_equal "/admin/login", last_request.url assert last_response.ok? end def test_redirection_connexion_au_tableau_de_bord post "/admin/login", :username => "foo", :password => "bar" assert_equal "/admin/dashboard", last_request.url assert last_response.ok? end end