为什么“rails server -e production”使它“无路由匹配”/“并且样式表没有加载?

时间:2011-03-13 06:02:05

标签: ruby-on-rails ruby-on-rails-3

它正在运行Rails 3.0.0或Rails 3.0.5(使用Ruby 1.9.2)

处于开发模式时

rails server

然后http://localhost:3000工作正常,http://localhost:3000/foos将加载stylesheet.css

但是当它

rails server -e production

然后突然间,http://localhost:3000给出了:

No route matches "/"

http://localhost:3000/foos可以运行,但未加载stylesheet.css并在浏览器中打开它显示:

No route matches "/stylesheets/scaffold.css"

生产与开发需要特殊的路线吗? (还是出于其他原因?)

1 个答案:

答案 0 :(得分:19)

您需要设置

 config.serve_static_assets = true
config/environments/production.rb中的

。它可能已经在那里被评论过了。

默认情况下,Rails不会在生产中自行提供静态文件,因为像Nginx或Apache这样的完整Web服务器无论如何都会自动为它们提供服务。