Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between `redirect` and `redirect to` in Sinatra

Tags:

ruby

sinatra

What is the difference between using redirect and redirect to in Sinatra? They both seem to default to the same status code. Is the to '/url' bit just some syntactic niceness to make the method more readable?

like image 956
loganhasson Avatar asked Feb 27 '14 16:02

loganhasson


1 Answers

The redirect method sends the HTTP header to redirect the client to a given URL, and the argument passed should be a fully qualified URL with a host (e.g. http://example.com/path, not just /path).

The to method converts a path to a full URL for your Sinatra app, allowing the resulting URL to be used in redirect. E.g. to('/path') would become http://yoursinatraapp/path.

like image 178
Jon Cairns Avatar answered Oct 16 '22 08:10

Jon Cairns