Get absolute (base) url in sinatra.
Posted
by berkes
on Stack Overflow
See other posts from Stack Overflow
or by berkes
Published on 2010-06-01T13:41:08Z
Indexed on
2010/06/01
13:43 UTC
Read the original article
Hit count: 244
Right now, I do a
get '/' do
set :base_url, "#{request.env['rack.url_scheme']}://#{request.env['HTTP_HOST']}"
# ...
haml :index
end
to be able to use options.base_url in the HAML index.haml. But I am sure there is a far better, DRY, way of doing this. Yet I cannot see, nor find it. (I am new to Sinatra :))
Somehow, outside of get, I don't have request.env available, or so it seems. So putting it in an include did not work.
How do you get your base url?
© Stack Overflow or respective owner