问题描述
当我在test / dev本地运行我的应用程序时,我的视图很好地呈现出来,而且一切都很开心。当我尝试导航到远程服务器/本地生产服务器上运行的相同erb文件时,出现以下错误:
ActionController :: RoutingError(没有路由匹配/stylesheets/scaffold.css)
我见过这里有类似的问题,但没有人能解决我的问题。我发现最接近的答案是这里的第一个答案:
据我所知,最好的办法是将我的web服务器配置为提供静态文件。如何在Heroku本地/在Heroku上执行此操作?
更新
raidfive的建议我将config.serve_static_assets从false更改为true,这解决了我的问题。但是,我发现它在production.rb中表示Apache或nginx应该已经在提供静态资产。以这种方式提供静态资产是否更好/更专业?如果是这样,如果我使用Heroku,如何达到期望的结果?
更新2
显然Heroku ,但我有一个额外的逗号导致恶作剧。我可以使用来追查麻烦。感谢您!
您是否使用Rails 3?默认情况下,Rails 3 / webrick在生产模式下不提供静态文件。您可以通过设置
config.serve_static_assets
至 true
在您的 production.rb
文件中。
When I run my app locally in test/dev my views come up nicely and everything is happy. When I try to navigate to those same erb files running on my remote server/local production server I get errors like the following:
ActionController::RoutingError (No route matches "/stylesheets/scaffold.css")
I've seen similar questions here on SO but none have been able to solve my problem. The closest thing I've found to an answer is the first answer here: Rails 404 error for Stylesheet or JavaScript files
As I understand it the best thing to do would be to configure my webserver to serve static files. How do I do this locally/on Heroku?
Update
As per raidfive's suggestion I changed config.serve_static_assets from false to true and this fixed my issue. However, I see that it says in production.rb that Apache or nginx should already be serving static assets. Is it any less good/professional to serve static assets in this way and if so how would I achieve the desired results if I'm using Heroku?
Update 2
Apparently Heroku does this automatically, I had an extra comma that was causing the mischief. I was able to look in the extended Heroku logs using the following tip to track down the trouble. Thanks SO!
Are you using Rails 3? By default Rails 3 / webrick does not serve static files in production mode. You can easily enable this by setting
config.serve_static_assets
to true
in your production.rb
file.
这篇关于Rails生产静态文件路由错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!