ruby-on-rails - Rails 应用程序未在弹性 beantalk aws 上加载 Assets

标签 ruby-on-rails ruby amazon-web-services asset-pipeline amazon-elastic-beanstalk

对于上下文,我基本上遵循了这个指南来设置我的 Rails 应用程序: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/

运行 Ruby 2.2 (Puma) 的 64 位 Amazon Linux 2015.03 v2.0.1

但是,我无法加载我的任何 Assets 。

这是我的 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

不过,我的 Assets 可以通过 heroku 正常加载。 (不过,我不打算再使用 heroku 了)

编辑 它看起来像是 rake assets:precompile 提供错误文件名的问题。例如:我编译的 css 文件是:“public/assets/application-79dc234c01a4f604b52fc53ff49ac89d.css”,但我得到一个 404 寻找“application.css”。将文件重命名为“public/assets/application.css”将正确加载它。

知道为什么会出现这种情况以及如何正确预编译它吗?

最佳答案

文件名后的这个字符串称为“摘要”,用于在文件内容发生变化时通知浏览器。您需要使用 View 助手(asset_path 等)来获取带有摘要的名称,或者您可以使用 config.assets.digest = false 关闭此功能

关于ruby-on-rails - Rails 应用程序未在弹性 beantalk aws 上加载 Assets ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32896633/

相关文章:

mysql - Rails 尝试插入时找不到用户记录

javascript - Rails 完成请求后动态推送内容

ruby-on-rails - before_filter 在使用 devise 和 jquerymobile 时不重定向

ruby-on-rails - 链接到旧的 Rails 文档

ruby - REGEX 匹配置信度为 100%,那么 99% 呢?

amazon-web-services - AWS Cloudformation ELB 运行状况检查 (verify_instance_health) 不适用于 Ubuntu

laravel - Laravel 5.2 的 AWS SES 400 错误请求响应

python - 如何使用 python boto3 显示我的 aws 帐户中的所有快照

ruby-on-rails - 如何在 win 7 上安装 caldecott?

ruby - Ruby 中的大乘法输出为负