【问题标题】:Rails 4 assets not loading in heroku after 'rake assets:precompile'在'rake assets:precompile'之后,Rails 4 资产未加载到 Heroku
【发布时间】:2013-11-27 11:25:57
【问题描述】:

这让我发疯了!我的应用程序在本地服务器上正常运行,但是当我上传到 heroku 时,css 和 js 文件没有更新。我阅读了使用 rake assets:precompile 进行预编译以解决问题,但后来我再次上传到 heroku,现在我的所有资产都没有加载!我已经尝试了预编译的所有变体,安装了 12factor gem,将一些配置设置从 false 变为 true,仍然没有发生!当我看控制台时,它说

[错误] ReferenceError:找不到变量:jQuery 全局代码(application-38ccb09605964287831a37a0d9faf188.js,第 1 行)

但我确实有 Jquery!它在本地运行良好!我不知道我做错了什么。

宝石文件

gem 'bootstrap-sass-rails'
gem 'rails_12factor', group: :production

gem 'rails', '4.0.0'

gem 'sqlite3', :group => [:development, :test]
group :production do
  gem 'thin'
  gem 'pg'
end

gem 'sass-rails', '~> 4.0.0'

gem 'uglifier', '>= 1.3.0'

gem 'coffee-rails', '~> 4.0.0'

gem 'jquery-rails'

gem 'jbuilder', '~> 1.2'

group :doc do
  # bundle exec rake doc:rails generates the API under doc/api.
  gem 'sdoc', require: false
end

生产.rb

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
config.assets.js_compressor = :uglifier
config.assets.compile = true
config.assets.digest = true
config.assets.version = '1.0'
config.log_level = :info
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.log_formatter = ::Logger::Formatter.new

【问题讨论】:

  • 你能运行heroku logs并显示它的内容吗?
  • 它有点长,所以我把它放在谷歌文档中。 docs.google.com/document/d/…
  • 好的..我今天早上登录了,现在我在本地的应用程序现在也无法运行..必须已经缓存或其他东西。
  • config.assets.debug = true 似乎已经解决了本地的问题,但仍然无法在 heroku 上工作
  • 运行 $ RAILS_ENV=production bundle exec rake assets:precompile 让我的 heroku 应用程序现在可以工作了。所以我想问题已经解决了..

标签: ruby-on-rails-4 loading assets precompile


【解决方案1】:

运行$RAILS_ENV=production bundle exec rake assets:precompile 使我的heroku 应用程序现在可以运行。所以我想问题已经解决了..

抱歉,我没有解释它为什么起作用

【讨论】:

  • 谢谢!这是一个非常令人沮丧的问题,这解决了它!谁会想到只在本地预编译资产并将它们推送到 Heroku 就可以了。
【解决方案2】:

简单运行

    $ bundle exec rake assets:precompile
    $ git add .
    $ git commit -am "assets precompiled locally"
    $ git push heroku master

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-07
    • 1970-01-01
    • 2013-09-13
    • 2018-07-09
    • 1970-01-01
    • 2016-12-16
    • 2015-05-27
    相关资源
    最近更新 更多