mattman (owner)

Fork Of

Revisions

gist: 130620 Download_button fork
public
Public Clone URL: git://gist.github.com/130620.git
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
The below Sinatra code works with URLs like:
 
/c/blahblah
 
and
 
/c/http://blah.com/something.php
or
/c/google.com
 
But doesn't work with:
 
/c/http://google.com?id=47&q=blahblah
 
all you get shown is:
 
"http://google.com" in the above case.
 
How can I get all of the values given in the URL that I'm giving to the app ??
test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
require 'rubygems'
require 'sinatra'
require 'haml'
 
set :haml, {:format => :html5 }
 
get '/' do
# haml "%p Hello whirled, it's: #{Time.now} on this server."
  @foo = Time.now
  haml :index
end
 
# straight grabbing what's after the slash - breaks if "http://" is present
get '/c/:url' do
  haml "%p You entered the URL #{params[:url]}."
end
 
# grabbing using regex to strip out the protocol string
get %r{/c/(http:\/\/)(.*)} do
  haml "%p You entered the URL #{params[:captures][1]}."
end
 
# grabbing what's after the slash with a * operator - still doesn't get parameterised URLs (something.com?id=47)
get '/c/*' do
  haml "%p You entered the URL #{params[:splat].to_s}."
end
 
# straight to the about page
get '/about' do
  haml :about
end