Search code examples
rubyrackcamping

What's the base URL for my app?


In Camping/Rack, how can I get the base URL for my app? I want to know so I can put it in an email it sends.

It might be (in development)

or

http://localhost:9292

or

http://localhost:80/game

or in production

http://fancy-snake.heroku.com

Solution

  • Camping has a helper called URL which returns the absolute URL to your app:

    URL()               # => #<URL:http://test.ing/blog/>
    URL() + "view/12"   # => #<URL:http://test.ing/blog/view/12>
    URL("/view/12")     # => #<URL:http://test.ing/blog/view/12>