开发者

Paths for sinatra through jruby, tomcat

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?


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}" %>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜