git push heroku master
するとエラーが出てしまいます。
remote: ! Could not detect rake tasks remote: ! ensure you can run `$ bundle exec rake -P` against your app remote: ! and using the production group of your Gemfile. remote: ! rake aborted! remote: ! NameError: undefined local variable or method `config' for main:Object
試したこと
続けてエラーが出ており、前回のエラーは解決しましたが、前回までにやったことがエラーの原因の可能性もあるかもしれないので書いておきます。
- エラー1
- エラー2
remote: /tmp/build_319fb38fa8fa3b982e5d369cd184a217/vendor/bundle/ruby/2.4.0/gems/rake-12.3.1/exe/rake:27:in `<top (required)>' remote: Tasks: TOP => environment remote: (See full trace by running task with --trace) remote: remote: ! remote: ! Precompiling assets failed. remote: ! remote: ! Push rejected, failed to compile Ruby app. remote: remote: ! Push failed remote: Verifying deploy... remote: remote: ! Push rejected to quiet-sands-44976. remote: To https://git.heroku.com/quiet-sands-44976.git ! [remote rejected] master -> master (pre-receive hook declined) error: failed to push some refs to 'https://git.heroku.com/quiet-sands-44976.git'
解決
# config/application.rb config.assets.initialize_on_precompile = false
- エラー3 (現在のエラー)
$ RAILS_ENV=production bundle exec rake assets:precompile rake aborted! NameError: undefined local variable or method `config' for main:Object /home/yuis/share/aptnote/config/application.rb:9:in `<top (required)>' /home/yuis/share/aptnote/rakefile:4:in `require_relative' /home/yuis/share/aptnote/rakefile:4:in `<top (required)>' /home/yuis/.rbenv/versions/2.4.2/bin/bundle:23:in `load' /home/yuis/.rbenv/versions/2.4.2/bin/bundle:23:in `<main>' (See full trace by running task with --trace) $ rake assets:precompile RAILS_ENV=production rake aborted! NameError: undefined local variable or method `config' for main:Object /home/yuis/share/aptnote/config/application.rb:9:in `<top (required)>' /home/yuis/share/aptnote/rakefile:4:in `require_relative' /home/yuis/share/aptnote/rakefile:4:in `<top (required)>' (See full trace by running task with --trace)
config/application.rb:9:にはエラー2の対処として追記したconfig.assets.initialize_on_precompile = false
が書いてあります。これを抜くとエラー2が出てしまいます。
参考にしたページ
ruby on rails - heroku push error: "Could not detect rake tasks" - Stack Overflow
追記 (8/15)
ふと思ったのですが、config.assets.initialize_on_precompile = false
を書く場所は以下で合っていますでしょうか??
moduleの中に最初は書きましたが、そうすると依然として同様のエラーが出続けていたため、
module の外に書かなきゃいけないんだなと思い込んでいましたが、もしかして間違っていますか?
config\application.rb
require_relative 'boot' require 'rails/all' # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) config.assets.initialize_on_precompile = false module Aptnote class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. config.load_defaults 5.2 # config.assets.initialize_on_precompile = false # => Precompiling assets failed. # Settings in config/environments/* take precedence over those specified here. # Application configuration can go into files in config/initializers # -- all .rb files in that directory are automatically loaded after loading # the framework and any gems in your application. end end
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/11/01 07:06