1

I tried to deploy my code to heroku. It only work with

config.assets.initialize_on_precompile = false

in my application.rb despite I'm using Rails 4.2.3. But when I tried to use

heroku run rake db:migrate

It cannot work correctly with error:

Name Error: Undefined local variable or method config for main:Object

/app/config/application.rb:7 in `'

Here is my Gemfile

source 'https://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.3'
group :production do
#Use PG
gem 'pg'
end
group :development do
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
end
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0.1'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer',  platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0',          group: :doc

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use unicorn as the app server
# gem 'unicorn'

#Use Heroku
gem 'rails_12factor', group: 'production'   
#Use bootstrap
gem 'bootstrap', '~> 4.0.0.alpha3'
gem 'autoprefixer-rails'
#Use Redcarpet
gem 'redcarpet'
#Use SQLite
#gem 'sqlite3', '1.3.11'


# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

# Use debugger
# gem 'debugger', group: [:development, :test]

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin]

And here is application.rb

require File.expand_path('../boot', __FILE__)

require 'rails/all'

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
# Prevent initializing the application before assets are precompiled (required for heroku)
config.assets.initialize_on_precompile = false
Bundler.require(*Rails.groups)
module Blog
  class Application < Rails::Application
    # Settings in config/environments/* take precedence over those specified here.
    # Application configuration should go into files in config/initializers
    # -- all .rb files in that directory are automatically loaded.

    # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
    # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
    # config.time_zone = 'Central Time (US & Canada)'

    # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
    # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
    # config.i18n.default_locale = :de
  end
end

Any solutions for my stuck point?

The log when I tried : git push heroku master with config.assets.initialize_on_precompile = false put in production.rb

https://i.sstatic.net/9rXp9.png

Sorry I cannot put img since I'm newbie.

2
  • Please try rake db:migrate and see If it works localy, If it does not please post the output Commented Jan 27, 2016 at 0:01
  • I tried your way but it cannot work correctly * Here is the log: rake abborted! NameError: undefined local variable or method config' for main:Object c:/Users/khoi/Desktop/blog/config/application.rb:8:in <top (required)>' @Ezequiel Commented Jan 27, 2016 at 13:44

1 Answer 1

1

Remove config.assets.initialize_on_precompile = false from application.rb

If you need to have this line in your rails application it should go in: app/config/environments/production.rb

Sign up to request clarification or add additional context in comments.

3 Comments

I used your commend. It can use rake db:migrate now. But it cannot push to heroku. The picture I added in my question. Sorry for this inconvenience but I don't know how to push a log file in Git Bash
Could you please give me the next hint @Andrew Hendrie
if the answer solved your problem, please accept it. If you have another issue post another question with the appropriate code/errors and I'll be happy to help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.