【问题标题】:Rails 4 assets not being served in production on WindowsRails 4 资产未在 Windows 上投入生产
【发布时间】:2014-05-13 07:20:12
【问题描述】:

我目前遇到的问题与这篇文章中描述的完全相同:Rails not serving assets in production or staging environments

我在 Windows 7 的生产环境中运行 Rails 4.0.4(这很容易成为问题,不幸的是不能使用 Linux)。我已经运行 rake assets:clobber 以确保所有内容都已清理干净,然后运行 ​​RAILS_ENV=production rake assets:precompile 并成功运行,没有错误或警告。所有文件都出现在我的 public/assets 文件夹中,使用 Windows 资源管理器我可以查看 application.js 和 application.css 中的文本,并且图像可以正确显示。但是,当我尝试访问 localhost:3001/assets/application.js 时,它是空白的,与 application.css 相同,并且图像文件出现错误。每次更改设置和预编译后,我都会重新启动服务器。

当我查看显示页面渲染成功的日志时,没有像我在其他帖子中看到的“无路由匹配”错误。因此,正在找到资产,但由于某种原因,它们没有得到适当的服务。

这是我的production.rb:

ABC::Application.configure do

    config.cache_classes = true
    config.eager_load = true
    config.consider_all_requests_local       = false
    config.action_controller.perform_caching = true
    config.action_dispatch.x_sendfile_header = "X-Sendfile"
    config.serve_static_assets = true
    config.action_mailer.default_url_options = { :host => '' }
    config.i18n.fallbacks = true
    config.active_support.deprecation = :notify
    config.assets.js_compressor = :uglifier
    config.assets.css_compressor = :sass
    config.assets.compile = false
    config.assets.digest = true

end

任何帮助将不胜感激,我已经坚持了将近两天!

【问题讨论】:

    标签: windows ruby-on-rails-4 asset-pipeline


    【解决方案1】:

    就在我完成这个问题的输入时,我终于看到了另一个帖子,上面说正在设置标题但没有正文,这听起来像是我的问题。他们正在使用 nginx 并通过更改以下内容来解决问题:

    # 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
    

    看到我没有使用 Apache 或 nginx,我注释掉了这两行,最后我的资产得到了服务。事后看来似乎很明显,但我想我还是会发布这个,以防它帮助其他遇到同样问题的人。

    【讨论】:

      猜你喜欢
      • 2013-09-13
      • 1970-01-01
      • 1970-01-01
      • 2014-09-12
      • 1970-01-01
      • 2016-02-21
      • 1970-01-01
      • 2014-09-29
      相关资源
      最近更新 更多