这是一个Rails 4.2应用程序的app/assets/目录。
有3个Bootstrap的js和css文件。在部署到生产环境(ubuntu 12.1)之后,在服务器上进行了assets预编译(在suburi下部署):
RAILS_ENV=production bundle exec rake assets:precompile RAILS_RELATIVE_URL_ROOT=/mysuburi
这里是 production.rb
文件:
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_files = false #ENV['RAILS_SERVE_STATIC_FILES'].present?
config.assets.compress = true
config.assets.js_compressor = :uglifier
config.assets.compile = false
config.assets.digest = true
config.log_level = :debug
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.log_formatter = ::Logger::Formatter.new
config.active_record.dump_schema_after_migration = false
这里是 application.css.scss
的头部:
@import "bootstrap.min.css";
@import "bootstrap-theme.min.css";
@import "simple_form.css.scss";
@import "user_menus.css.scss";
在 application.js
中,它有:
//= require bootstrap.min
以下是在生产服务器上public/assets/目录下ls
命令的输出结果:
application-05cf37813d76c2bd659271403789374cc118f1a4e616ec220969577b79ff6514.css
application-375b4b5d8fc285716f4fdca966aa960912efe8292242df8f1a60b99d5caa4b02.js
authentify
banquet_coursex
banquetx
biz_workflowx
commonx
glyphicons-halflings-regular-5d234508037dc13a419ef6ce48f3fc73dbb477f1a162c052b872182b494e626e.svg
glyphicons-halflings-regular-bd18efd3efd70fec8ad09611a20cdbf99440b2c1d40085c29be036f891d65358.ttf
glyphicons-halflings-regular-f495f34e4f177cf0115af995bbbfeb3fcabc88502876e76fc51a4ab439bc8431.eot
glyphicons-halflings-regular-fc969dc1c6ff531abcf368089dcbaf5775133b0626ff56b52301a059fc0f9e1e.woff
jquery-ui
searchx
state_machine_logx
user_manualx
user_menus-7c46e17f4172c2a954eeaf85e80b4e030d1ed0fb3927288bbe07eeb4fb8cbfc5.css
通过与其他Rails应用程序进行比较,我们发现在/assets下缺少manifest.json。 我们尝试了在config/environment/production.rb中使用各种配置选项,但都没有成功。唯一在生产服务器上可行的选择是实时编译的config.assets.compile = true(不建议)。导致资产预编译失败的是我们的代码存在什么问题?更新:我们已经从头开始重建了Rails应用程序,但资产问题仍然存在。此资产预编译问题可能与config/production.rb和config/initializers/aseets.rb中的设置无关,正如我们怀疑的那样。回滚bundler和rake的版本也没有帮助。同一组Bootstrap css和js文件已在另一个运行于相同生产服务器上的Rails 4.2应用程序中使用而没有出现问题。
config.assets.precompile += ['bootstrap.min.js','b...
]。这仅适用于外部资产,除非在清单中未指定。 - maximus ツ@maximus
,是的,在另一个完全相同的Rails 4.2应用程序中,我们没有在assets.rb
中显式包含那些CSS或JS文件。但是对于这个应用程序不是这样的。如果不包括那些Bootstrap JS/CSS,则在资产预编译后它们根本不会被指纹化。 - user938363@Mauricio Gracia
,是的,但这个问题可能是不同的。在我们的情况下,在资产预编译中没有错误。问题只会在登录网站并打开页面时显示出来。此外,如果在production.rb
中设置config.assets.compile = true
(所谓的现场编译,可能性能较差),那么资产将正确显示在页面上。 - user938363