Sinatra learning problem [$_GET]

Hi !

Im learning Sinatra, while i was doing that… i realize that i didnt
understand nothing about passing variables via URL [GET]

i understand that i can:

get ‘/:something’ do
“Print #{params[:something]}!”

but how may i create that var called “something” ?
SCRIPT-> create “something”
THEN-> GET “something”

thats my question :slight_smile:

sorry my english!


On 05/21/2012 10:23 AM, cristian d. wrote:

For any url that looks like “/blah” the variable “params[:something]”
will be set to whatever comes after the “/”

For example (using curl):

$ curl localhost:5000/blah
Print blah!
$ curl localhost:5000/whatever
Print whatever!
$ curl localhost:5000/something
Print something!
$ curl localhost:5000/whee
Print whee!

The “:something” in your route just determines the name of the

See Sinatra: README


let me see if i understand, so for example i have two scripts like:


if i want to sent a VAR to tho.rb i will just

redirect to two.rb/something=1

like that ?

Thanks Justin !!!

pd: and for POST like in a ?

On 05/21/2012 12:07 PM, cristian d. wrote:

Thanks Justin !!!

pd: and for POST like in a ?

If all you want is to access the query parameters (the key-value pairs
after “?” in a URL), then you do not need to have “:something” in your

If you have something like this:

get ‘/’ do
“Print #{params[:something]}!\n”

You can access it like (note the “?”):

$ curl localhost:5000/?something=hi
Print hi!

POST and GET parameters are both stored in the “params” hash.