Anconia
Anconia

Reputation: 4028

Failing to push to heroku

I am attempting to push my rails 3.2.12 app to heroku, which is configured with a postgres database. The first time I ran git push heroku master I received the below error.

Running: rake assets:precompile
rake aborted!
could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?

After some troubleshooting I came across this post and put the following line in my config/application.rb file:

config.assets.initialize_on_precompile = false

I then ran heroku run rake db:migrate to begin populating the heroku database and received the following error:

Running rake db:create attached to terminal... up, run.4115
rake aborted!
undefined local variable or method `config' for main:Object
/app/config/application.rb:5:in `<top (required)>'
/app/Rakefile:5:in `require'
/app/Rakefile:5:in `<top (required)>'

Funny enough, line 5 of application.rb was the previous line I added:

config.assets.initialize_on_precompile = false

Lastly, I noticed that I can't start the database locally with the above line in my application.rb file - I receive the following error:

config/application.rb:5:in `<top (required)>': undefined local variable or method `config' for main:Object (NameError)

This issue seems like a catch 22. How can I deploy to heroku without altering the application.rb file as well as run it on my local server?

Upvotes: 3

Views: 1953

Answers (2)

user4068877
user4068877

Reputation: 1

I tried adding

config.assets.initialize_on_precompile = false

to "config/application.rb" and uploaded my project to heroku, it got uploaded without any errors and its not working, even rake commands are not working on heroku.

I found on this article on heroku: https://devcenter.heroku.com/articles/rails-4-asset-pipeline which says add

config.serve_static_assets = true

to your config/application.rb then its working properly. It is precompiling properly when tested with "rake assets:precompile" on my computer . And my project got uploaded properly and showing things soo coool.

Upvotes: 0

fontno
fontno

Reputation: 6852

Make sure config.assets.initialize_on_precompile = false is in the correct place like this:

module YourApplicationName
  class Application < Rails::Application

    config.assets.initialize_on_precompile = false

Make sure to restart everything.

Also, if the above doesn't work, a temporary work around would be to change your Gemfile to:

group :development, :test do
  gem 'sqlite3'
end

group :production do
  gem 'pg'
end

Then run bundle install --without production

Heroku does not recommend using a different database for development and production. However This will work and I have used it many times to get up and running easily

Upvotes: 3

Related Questions