small medium large xlarge

28 Jan 2009, 14:57
Alex Rudyk (5 posts)

Hi Adam

Got small problem with first exercise from first screencast.

Here is the code for exercise:

get '/:hash' do
  url = @shorten.lookup(params[:hash])
  redirect url.url

Final line redirects me to instead of

And I see this sinatra page

Try this:
get '/' do
  "Hello World"

I’ve tried original code from screencast and got the same result. My sinatra version is, ruby 1.8.6, mac os x

So I wonder, why my behavior is differ from your results. Do you have any idea?


28 Jan 2009, 21:50
Matthew Hawkins (1 post)

Did you enter your original URL as or just

If you entered the latter, the string ‘’ is getting returned by ‘url.url’. Since there is no http in the url, the redirect assumes the string ‘’ represents a path on the current site.

30 Jan 2009, 15:30
Adam Keys (4 posts)

Alex, Matthew has the right idea here. The browser is interpreting the redirect as a URL relative to localhost, instead of an absolute URL. Exercise for the reader: add some validation to make sure the submitted URL starts with ‘http://’.

Great find Matthew!

03 Feb 2009, 18:49
Alex Rudyk (5 posts)

Thx a lot. It works now

You must be logged in to comment