1. Technology
You can opt-out at any time. Please refer to our privacy policy for contact information.

Sinatra URL Matching


In addition to accessing the parameters through the params hash, you can also access them using block parameters. When using multiple parameters, they're assigned in the same order they appear in the URL.

#!/usr/bin/env ruby
require 'rubygems'
require 'sinatra'

get '/hello/:name' do|name|
  "Hello #{name}"
  # Also available via params hash
  # "Hello #{params[:name]}!"
  1. About.com
  2. Technology
  3. Ruby
  4. Tutorials
  5. Sinatra
  6. Named Parameters Through Block Parameters

©2014 About.com. All rights reserved.