我有一个 Rails 应用程序,其静态内容位于 public
目录(例如 public/index.html
)中,并且在嵌套子目录中包含其他静态内容(例如 public/one/两个/index.html
)。
如果我通过 script/server
在本地运行所有静态内容,但当我将其上传到 Heroku 时,所有静态内容都会正确提供 顶级页面加载正确,但嵌套内容返回 404。
我找到了许多资源(例如 这个问题)讨论了 Rails 中的静态内容,但它们似乎都假设一个相当简单的结构,只有一个目录包含所有文件。
有什么办法可以解决这个问题吗?
I have a rails application with static content in the public
directory (e.g. public/index.html
) and additional static content in nested subdirectories (e.g. public/one/two/index.html
).
All the static content is served correctly if I run it locally via script/server
but when I upload it to Heroku the top-level page loads correctly but the nested content returns a 404.
I've found a number of resources (for example this question) which discuss static content in rails but they all seem to assume a fairly simple structure with a single directory containing all the files.
Is there any way I can fix this?
发布评论
评论(2)
如果您有一个非常简单的 Web 应用程序(例如,主要包含静态内容),则在 Sinatra “http://heroku.com” rel="nofollow noreferrer">Heroku 的设置要简单得多,并且可以防止此类问题。
If you have a very simple web application (with mostly static content, say) then using Sinatra on Heroku is much simpler to set up and prevents this type of problem.
您可以在 Heroku 上提供静态内容,而无需编写任何“代码”...您只需告诉“Rack”中间件内容在哪里(如本帮助文章中所述):
http://devcenter.heroku.com/articles/static-sites-on-heroku
You can serve up static content on Heroku without writing any "code" at all... you just need to tell the "Rack" middleware where the content is (as detailed in this help article):
http://devcenter.heroku.com/articles/static-sites-on-heroku