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]}!”
end
but how may i create that var called “something” ?
SCRIPT-> create “something”
URL/:something
THEN-> GET “something”
thats my question 
sorry my english!
Regards!
On 05/21/2012 10:23 AM, cristian d. wrote:
end
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
parameter.
See Sinatra: README
-Justin
let me see if i understand, so for example i have two scripts like:
one.rb
two.rb
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 ?
dlucca
4
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
route.
If you have something like this:
get ‘/’ do
“Print #{params[:something]}!\n”
end
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.
-Justin