Params is just a hash. Params will not persist across different sinatra route.
The params created in the first route, won't exist in the second route:
get '/*/*/:first/love' do
end
get "/got" do
end
if you set the sinatra route like so, then params is going to look like that
get '/:first' do
end
http://apps.com/awesome
{"splat"=>[], "captures"=>["awesome"], "first"=>"awesome"}
The "splat" is to fill in the gap that the sinatra creator do not know what to name the key of the params hash
get '/*' do
end
http://apps.com/awesome
{"splat"=>["awesome"], "captures"=>["awesome"]}
The "captures" will capture everything that is entered into the URL that is not a parameter.
get '/*/*/:first/love' do
binding.pry
end
# here love is just a normal link name, not a params
http://apps.com/awesome/possum/hate/love
{"splat"=>["awesome", "possum"], "captures"=>["awesome", "possum", "hate"], "first"=>"hate"}
splat will capture the first two * which is "awesome" and "possum".
:first will capture "hate"
all is captured in captures.
Params hash will capture data from url "/:data", or HTML form post, or query string "/?name=data"
The params created in the first route, won't exist in the second route:
get '/*/*/:first/love' do
end
get "/got" do
end
if you set the sinatra route like so, then params is going to look like that
get '/:first' do
end
http://apps.com/awesome
{"splat"=>[], "captures"=>["awesome"], "first"=>"awesome"}
The "splat" is to fill in the gap that the sinatra creator do not know what to name the key of the params hash
get '/*' do
end
http://apps.com/awesome
{"splat"=>["awesome"], "captures"=>["awesome"]}
The "captures" will capture everything that is entered into the URL that is not a parameter.
get '/*/*/:first/love' do
binding.pry
end
# here love is just a normal link name, not a params
http://apps.com/awesome/possum/hate/love
{"splat"=>["awesome", "possum"], "captures"=>["awesome", "possum", "hate"], "first"=>"hate"}
splat will capture the first two * which is "awesome" and "possum".
:first will capture "hate"
all is captured in captures.
Params hash will capture data from url "/:data", or HTML form post, or query string "/?name=data"
Comments
Post a Comment