【问题标题】:javascript not running on heroku with rails 3.1javascript没有在带有rails 3.1的heroku上运行
【发布时间】:2015-06-18 14:00:54
【问题描述】:

我已将一个 Rails 3.0 应用程序迁移到 Heroku 上的 3.1。它在 cedar 堆栈上运行,一切都很好,只是应用程序的 javascript 无法运行。 application.js 文件已编译并且看起来与它应有的一样。可以通过访问 myapp.com/assets/application.js 来访问它。它只是没有运行!

如果我在本地运行应用程序,javascript 可以工作,所以我怀疑一定有一些我遗漏的简单配置问题。这是我的 production.rb 文件:

FloridaBirdTrail::Application.configure do
  # Settings specified here will take precedence over those in config/application.rb

  # Code is not reloaded between requests
  config.cache_classes = true

  # Full error reports are disabled and caching is turned on
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true

  # Disable Rails's static asset server (Apache or nginx will already do this)
  config.serve_static_assets = true

  # Compress JavaScripts and CSS
  config.assets.compress = true

  # Send deprecation notices to registered listeners
  config.active_support.deprecation = :notify
end

编辑

将 production.rb 的内容替换为 development.rb 的内容至少允许我的一些 javascript 运行(gmap3 不工作,出于某种原因)。但是哪些设置会产生影响?

【问题讨论】:

    标签: javascript ruby-on-rails-3 heroku ruby-on-rails-3.1


    【解决方案1】:

    打开您的 application.rb 文件并确保您的 Bundler 要求语句如下所示:

    Bundler.require *Rails.groups(:assets)
    

    默认是这样的

    # If you precompile assets before deploying to production, use this line
    Bundler.require *Rails.groups(:assets => %w(development test))
    # If you want your assets lazily compiled in production, use this line
    # Bundler.require(:default, :assets, Rails.env)
    

    【讨论】:

      【解决方案2】:

      手动预编译对我有用。

      bundle exec rake assets:precompile 在你推送到 heroku 之前。

      【讨论】:

        【解决方案3】:

        【讨论】:

        • 嗨,谢谢,但是我在雪松上。我已经多次查看 Heroku 的文档,但没有找到任何关于为什么我的 javascript 没有运行的线索。
        • 你还做了哪些其他调试?如果您在 application.js 中放置一个 alert(),它会触发吗?当您访问 myapp.com 时,是否包含 javascript? Firebug 是否验证对资产的请求是否成功?
        • javascript 包含在标头中,我可以转到该资产并查看它,它与我在本地运行应用程序并且 javascript 工作时一样。插入 alert() 调用不起作用。我现在就和 Firebug 核对一下,谢谢!
        • 萤火虫中没有控制台错误。我也可以从 heroku 跟踪日志,也没有错误。
        • 问题一定是我在服务器上运行时某些javascript正在爆炸。但为什么会这样呢?
        【解决方案4】:

        我遇到了一些 Javascript 问题(Heroku 上的服务器端,本地一切都很好),当我 * 将我所有的 Javascript 移到一个单独的文件中,而不是 application.js
        * 从 application.js 中删除了 require_tree,而是按名称调用了我想要的每个 javascript
        * 从我的 app/assets/javascript 文件夹中删除 bootstrap.js

        我的猜测是编译以某种方式搞砸了。

        【讨论】:

          【解决方案5】:

          我希望您在最新的 Heroku 推送之前对资产进行了本地预编译(如上述回复之一所述)。 请检查您的系统是否阻止 JavaScript 的执行。为此,在您使用 Heroku 应用程序时打开控制台,并检查异常情况。如果您看到与 JavaScript 相关的异常被阻止,则可能是问题所在。就我而言,同样的事情发生了,不幸的是,我无法对此做任何事情,因为我没有管理员权限。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2012-02-14
            • 1970-01-01
            • 1970-01-01
            • 2016-12-17
            • 1970-01-01
            • 2011-12-17
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多