Rails生产静态文件路由错误 [英] Rails production static files routing error

查看:97
本文介绍了Rails生产静态文件路由错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在test / dev本地运行我的应用程序时,我的视图很好地呈现出来,而且一切都很开心。当我尝试导航到远程服务器/本地生产服务器上运行的相同erb文件时,出现以下错误:

  ActionController :: RoutingError(没有路由匹配/stylesheets/scaffold.css)

我见过这里有类似的问题,但没有人能解决我的问题。我发现最接近的答案是这里的第一个答案:样式表或JavaScript文件的Rails 404错误



据我所知,最好的办法是将我的web服务器配置为提供静态文件。如何在Heroku本地/在Heroku上执行此操作?



更新

raidfive的建议我将config.serve_static_assets从false更改为true,这解决了我的问题。但是,我发现它在production.rb中表示Apache或nginx应该已经在提供静态资产。以这种方式提供静态资产是否更好/更专业?如果是这样,如果我使用Heroku,如何达到期望的结果?



更新2



显然Heroku 会自动执行此操作,但我有一个额外的逗号导致恶作剧。我可以使用查看扩展的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生产静态文件路由错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆