Reputation: 281
While developing a Sinatra app to run behind thin, paths are pretty easy.
Now that I'm launching via a warbled war file in tomcat, things have changed. The root is now one more level deep (/warFileName/
) and relative addresses are relative to the route/url, so if I have two routes get 'dostuff' and get 'subdir/dostuff', sourcing any files (js, css, images) is different between the two (the first I can just do 'js/blah.js'
and it'll properly look in public/js
, the second it will look in subdir/js
and fail). And, I can't do a root slash anymore (/js
), because of tomcat pushing things a level deep as I said before (/warFileName/subdir/doStuff
).
Assuming I don't want to hardcode /warFileName/
into all my image/js/css/etc references, and I'd rather not have my routers pass stuff on to haml like @root = ".."
or @root = ""
depending of if we're in a pseudo-subdirectory or not, is there an elegant way of handling this?
Upvotes: 1
Views: 345
Reputation: 11
Using the Sinatra URL helper is the best way to handle this.
<%= url '/path' %>
or, if you want to eval some Ruby inside the URL path:
<%= url "/path/#{foo}" %>
Upvotes: 1