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

它运行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" 

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

你需要设置

  config.serve_static_assets = true 

config/environments/production.rb 。 它可能已经在那里被评论出来了。

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