本文介绍了Rails不会加载生产环境中位于公共目录中的资产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,我在公共目录中拥有资产(因为简单)
Hello i have assets in public directory (because of simplicity)
在我加载的布局中
<link href="/bootstrap/css/bootstrap.css" rel="stylesheet">
<link href="/assets/css/jumbotron.css" rel="stylesheet">
<link href="/assets/css/application.css" rel="stylesheet">
在开发中效果很好,但在生产资产中未加载.
and in Development it works well but in Production assets are not loaded.
我的 Development.rb
Web::Application.configure do
config.cache_classes = false
config.whiny_nils = true
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.action_mailer.raise_delivery_errors = false
config.active_support.deprecation = :log
config.action_dispatch.best_standards_support = :builtin
config.active_record.mass_assignment_sanitizer = :strict
config.active_record.auto_explain_threshold_in_seconds = 0.5
config.assets.compress = false
config.assets.debug = true
end
我的 Production.rb
Web::Application.configure do
config.cache_classes = false
config.consider_all_requests_local = true # default false, zobrazuje errory
config.action_controller.perform_caching = false # default true
config.serve_static_assets = false
config.assets.compress = true
config.assets.compile = true # default false
config.assets.digest = true
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
end
推荐答案
这是因为您拥有
config.serve_static_assets = false
在您的production.rb
文件中.
从轨道配置指南:
就像该指南所建议的那样,您真的不应该依赖通过Rails应用程序从public/
提供服务的资产,最好让Web服务器(例如Apache或Nginx)处理提供服务的资产以提高性能.
And like that guide suggests, you really shouldn't rely on serving assets from public/
via your Rails app, it is better to let the web server (e.g. Apache or Nginx) handle serving assets for performance.
这篇关于Rails不会加载生产环境中位于公共目录中的资产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!