Is there a way to refer to the root URL of my Sinatra app? Say in one of the views I'd like to do the following:
<a href="<%= ROOT_PATH/cats %>">Show all cats</a>
Does Sinatra provide a magic helper for ROOT_PATH
or it's equivalent?
It should be accessible through request.base_url
Which is implemented by rack using:
def base_url
url = "#{scheme}://#{host}"
url << ":#{port}" if port != DEFAULT_PORTS[scheme]
url
end
There is also the uri
helper
#uri(addr = nil, absolute = true, add_script_name = true) ⇒ Object
Also known as:
url
,to
Generates the absolute URI for a given path in the app. Takes Rack routers and reverse proxies into account.
For your example:
<a href="<%= uri('/cats') %>">Show all cats</a>