【问题标题】:Assets only work in dev if I precompile如果我预编译,资产仅在开发中工作
【发布时间】:2012-08-03 19:00:03
【问题描述】:

因此,我们已将应用程序从 rails 3.0.7 升级到 rails 3.2。我们部署到heroku,所以我们在这样做之前在本地预编译。现在我遇到了这个问题,如果我先预编译,我的 js 文件只能在 dev 本地工作。当然,这意味着如果我更改某些内容,我必须重新进行预编译。我试图做一个资产:清洁,但后来我的 js 停止工作。或者更确切地说,它不能正常工作。见here

我还尝试将我的 config.assets.prefix 设置为“assets-dev”,以便将它们从不同的位置提供服务。我的其他 Rails 项目没有这个问题。这是我在 environment/development.rb 中的相关设置

  # Do not compress assets
  config.assets.compress = false

  #compile on the fly
  config.assets.compile = true

  # Expands the lines which load the assets
  config.assets.debug = true

  # Server assets out of asset-dev so they won't conflict with precompiles
  config.assets.prefix = "assets-dev"

有谁知道如何解决这个问题?

【问题讨论】:

    标签: ruby-on-rails-3 asset-pipeline


    【解决方案1】:

    我很确定你不需要在 environment/development.rb 中

    config.assets.compile = true
    

    【讨论】:

    • 你是对的。但这并不能解决问题。它仍然没有在我的文档中运行任何代码。
    • 您的 Web 开发人员工具中的脚本是否出现 404?路径是什么?他们匹配吗?
    • 不,它正在加载脚本。 Chrome 也将它们显示为已加载。它只是没有在我的文档中运行任何东西。我在我的 $(document.ready) 行上放了一个断点,它击中了它,但里面什么都没有。请参阅此链接。 link
    • 制作一个简单的 test.html.erb 并在其中:
    • 我想知道您是否有一些 Chrome 插件导致问题?
    猜你喜欢
    • 2012-07-28
    • 1970-01-01
    • 1970-01-01
    • 2017-10-13
    • 1970-01-01
    • 2015-12-14
    • 1970-01-01
    • 1970-01-01
    • 2019-11-20
    相关资源
    最近更新 更多