部署时,我的haml视图在我的public/css文件夹中找不到css文件,但设法在localhost上找到它

部署时,我的haml视图在我的public/css文件夹中找不到css文件,但设法在localhost上找到它,css,ruby,sinatra,haml,passenger,Css,Ruby,Sinatra,Haml,Passenger,我的应用程序运行在Sinatra上,并使用Passenger部署在Apache web服务器上。我的目录结构如下: approot ` public ` css - bootstrap.css ` uploads - empty.txt ` tmp - restart.txt ` views - success.haml - upload.haml - config.ru - myapp.rb 内部上传。haml %link(rel="stylesheet"

我的应用程序运行在Sinatra上,并使用Passenger部署在Apache web服务器上。我的目录结构如下:

approot
` public
  ` css
    - bootstrap.css
  ` uploads
    - empty.txt
` tmp
  - restart.txt
` views
  - success.haml
  - upload.haml
- config.ru
- myapp.rb
内部上传。haml

%link(rel="stylesheet" href="css/bootstrap.css")
当我在localhost:4567上运行这个应用程序时,CSS的加载非常好。但是,当我在web服务器上部署它时,CSS不会加载

在我的web服务器上,通过以下方式访问应用程序:
rubyapps.mydomain.com/appname

如果我键入:
rubyapps.mydomain.com/appname/css/bootstrap.css
,我就能很好地看到css文件的内容

完全困惑,不了解Sinatra如何处理这种情况,寻求一些帮助。

也许是这样

%link(rel="stylesheet" href="../public/css/bootstrap.css")
或者


您可能需要使用Sinatra的


不,不幸的是没有。我第一件事就试过了。问题是,当我“查看源代码”时,我可以看到正在生成的HTML文件链接到“css/bootstrap.css”,我的URL在这一点上是——如果我手动键入,它实际上会显示文件。好的,我所做的是,将appname添加到样式表link中,即%link(rel=“stylesheet”href=“appname/css/bootstrap.css”)它成功了。但是,现在这意味着在我的本地主机上,它将被破坏:/
%link(rel="stylesheet" href="/css/bootstrap.css")
For generating URLs you should use the url helper method, for instance, in Haml:

%a{:href => url('/foo')} foo

It takes reverse proxies and Rack routers into account, if present.

This method is also aliased to to (see below for an example).