Rails应用程序未在弹性beantalk aws上加载资产 [英] Rails app not loading assets on elastic beanstalk aws
问题描述
对于上下文,我基本上遵循此指南来设置我的Rails应用程序:
For context, I essentially followed this guide to get my rails app set up: https://medium.com/@jatescher/how-to-set-up-a-rails-4-2-app-on-aws-with-elastic-beanstalk-and-postgresql-3f9f29c046e2
我的应用程序现在正在AWS上运行: http://ems-heroes-dev.elasticbeanstalk.com/
My app is now running on AWS: http://ems-heroes-dev.elasticbeanstalk.com/
运行Ruby 2.2(Puma)的64位Amazon Linux 2015.03 v2.0.1
64bit Amazon Linux 2015.03 v2.0.1 running Ruby 2.2 (Puma)
但是,我无法加载任何资产.
However, I can't get any of my assets to load.
这是我的config/environments/production.rb:
Here is my config/environments/production.rb:
EmsHeroes::Application.configure do
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = true
# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
config.assets.compress = true
config.assets.compile = true
# Bower asset paths
root.join('vendor', 'assets', 'components').to_s.tap do |bower_path|
config.sass.load_paths << bower_path
config.assets.paths << bower_path
end
# Precompile Bootstrap fonts
config.assets.precompile << %r(bootstrap-sass/assets/fonts/bootstrap/[\w-]+\.(?:eot|svg|ttf|woff2?)$)
# Minimum Sass number precision required by bootstrap-sass
::Sass::Script::Value::Number.precision = [8, ::Sass::Script::Value::Number.precision].max
config.less.paths << "#{Rails.root}/lib/less/protractor/stylesheets"
config.less.compress = true
# Generate digests for assets URLs.
config.assets.digest = true
config.assets.enabled = true
# Version of your assets, change this if you want to expire all your assets.
config.assets.version = '1.0'
# Specifies the header that your server uses for sending files.
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
config.force_ssl = false
config.log_level = :info
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.log_formatter = ::Logger::Formatter.new
end
我的资产通过heroku正常加载. (但是,我不再打算使用heroku了)
My assets are loading fine via heroku though. (However, I dont plan on using heroku any more)
编辑 看起来rake资产存在问题:预编译提供了错误的文件名.例如:我的编译后的CSS文件是:"public/assets/application-79dc234c01a4f604b52fc53ff49ac89d.css",但我正在获取404,查找"application.css".将文件重命名为"public/assets/application.css"将正确加载该文件.
EDIT It looks like its an issue with rake assets:precompile providing the wrong file names. Ex: My compiled css file is: "public/assets/application-79dc234c01a4f604b52fc53ff49ac89d.css" but Im getting a 404 looking for "application.css". Renaming the file to "public/assets/application.css" will load it properly.
有人知道为什么会发生这种情况,以及如何使它正确地进行预编译吗?
Any idea why this would be the case and how I can get it to precompile properly?
推荐答案
文件名后的此字符串称为摘要",用于在文件内容更改时通知浏览器.您需要使用视图助手(asset_path等)来通过摘要获取名称,也可以使用config.assets.digest = false
This string after file name is called "digest", it's used to notify browser when file content changes. You need to use view helpers (asset_path, etc) to get name with digest, or you can turn off this feature with config.assets.digest = false
这篇关于Rails应用程序未在弹性beantalk aws上加载资产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!