1. Computing

Sinatra URL Matching

By

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]}!"
end
  1. About.com
  2. Computing
  3. Ruby
  4. Tutorials
  5. Sinatra
  6. Named Parameters Through Block Parameters

©2014 About.com. All rights reserved.