简体   繁体   English

rails 3.1.3:尝试在生产环境中本地运行,资产管道不工作

[英]rails 3.1.3: trying to run locally in production, asset pipeline not working

My app runs fine in development mode.我的应用程序在开发模式下运行良好。

When I run in production mode using RAILS_ENV=production rails s none of my.css or.js files get loaded.当我使用RAILS_ENV=production rails s在生产模式下运行时,我的 .css 或 .js 文件均未加载。 (I did precompile assets, using RAILS_ENV=production bundle exec rake assets:precompile .) (我使用RAILS_ENV=production bundle exec rake assets:precompile 。)

The webrick log shows: webrick 日志显示:

ActionController::RoutingError (No route matches [GET] "/assets/application-a73ce43be7bf75953cd0c60b2b4a7eb0.js"): ActionController::RoutingError(没有路由匹配[GET]“/assets/application-a73ce43be7bf75953cd0c60b2b4a7eb0.js”):

and

ActionController::RoutingError (No route matches [GET] "/assets/application-986dd79830088c416c1632c12999ec69.css"): ActionController::RoutingError(没有路由匹配[GET]“/assets/application-986dd79830088c416c1632c12999ec69.css”):

The files were compiled (according to the log\production.log file) and my public/assets directory does show those files with and without the fingerprint:这些文件已编译(根据 log\production.log 文件),我的 public/assets 目录确实显示了那些带有和不带有指纹的文件:

ls public/assets
application-986dd79830088c416c1632c12999ec69.css
application-986dd79830088c416c1632c12999ec69.css.gz
application-a73ce43be7bf75953cd0c60b2b4a7eb0.js
application-a73ce43be7bf75953cd0c60b2b4a7eb0.js.gz
application.css
application.css.gz
application.js
application.js.gz

Rails doesn't serve static assets in production mode by default.默认情况下,Rails 不会在生产模式下提供 static 资源。 If you want to disable this and serve the static assets, update your config/environments/production.rb file with this:如果您想禁用它并提供 static 资产,请使用以下内容更新您的config/environments/production.rb文件:

config.serve_static_assets = true

The reasoning behind Rails' default configuration is that it assumes you'll be running behind a standard web server in production mode (Apache, Nginx, etc.) which will then proxy the requests to your Rails app. Rails 默认配置背后的原因是它假设您将在生产模式下运行在标准 web 服务器(Apache、Nginx 等)之后,然后它将请求代理到您的 Rails 应用程序。 Since the assets are precompiled, Apache/Nginx/etc.由于资产是预编译的,Apache/Nginx/等。 can directly serve them without needing to talk to your Rails processes.可以直接为它们提供服务,而无需与您的 Rails 进程对话。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM