简体   繁体   中英

Rails app works locally but not when deployed to Heroku

my app was working locally. I deployed to heroku and am getting an application error. I cant seem to figure out what is wrong. Posting logs below, does anything stick out?

error

An error occurred in the application and your page could not be served. Please try again in a few moments.

If you are the application owner, check your logs for details.

logs

heroku logs

2014-07-04T04:40:15.871014+00:00 heroku[web.1]: State changed from starting to crashed
2014-07-04T04:40:16.982435+00:00 heroku[router]: at=error code=H10 desc="App crashed"     method=GET path="/" host=kitchen-ninja.herokuapp.com request_id=aa152804-e6f0-4a2f-9c27-   c9fb580272f3 fwd="100.1.249.244" dyno= connect= service= status=503 bytes=
2014-07-04T04:40:17.620440+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=kitchen-ninja.herokuapp.com request_id=a3c43716-35b3-43b5-9426-fb2f3f400c1b fwd="100.1.249.244" dyno= connect= service= status=503 bytes=
2014-07-04T04:40:17.783162+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=kitchen-ninja.herokuapp.com request_id=2a8c63d7-3906-48c7-85de-abe64c2fd247 fwd="100.1.249.244" dyno= connect= service= status=503 bytes=
2014-07-04T04:40:15.860319+00:00 heroku[web.1]: Process exited with status 1

gemfile

source 'https://rubygems.org'
ruby '2.0.0'


gem 'rails', '4.0.2'
gem 'pg', '0.15.1'
gem 'mail_form', '~> 1.5.0.rc'
gem 'less-rails'
gem 'therubyracer', '~> 0.12.1'
gem 'simple_form'
gem 'pony'
gem 'sass-rails', '4.0.1'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
gem 'jquery-turbolinks'
gem 'jbuilder', '1.0.2'
gem 'paperclip', '4.1'
gem 'devise'

group :development do
    gem 'rspec-rails', '2.13.1'
    gem 'guard-rspec', '2.5.0'
end 

group :test do

end

group :doc do
  gem 'sdoc', '0.3.20', require: false
end

group :production do
    gem 'rails_12factor', '0.0.2'
end

After you have to deployed to heroku, you need to run rake db:migrate before it starts work. Go to the folder you pushed the app from and do a

heroku run rake db:migrate

This should fix the 503 errors you are having.

There are two types of error of Rails apps on Heroku:

Heroku

在此输入图像描述

This means Heroku has a problem at platform-level (IE Rails cannot be loaded). This is typically a database issue, which can be resolved by either ensuring your db is created, or running the heroku run rake db:migrate command from your CMD

--

Rails

在此输入图像描述

This is a Rails specific error, caused when you hit a Rails app which has problems internally . This will only show if the entire Heroku platform is running well, meaning if you have a db set up etc - meaning something inside your code is broken


The difference here is that one error is platform specific, whilst the other is application specific. If you have the above ( Heroku ) error, you need to make sure you can fix any of the issues you have on the Heroku platform itself -- which can be done by using:

$ heroku run rake db:migrate

This is, of course, considering you have a database set up for your Rails application. If this is the case, you need to make sure you have a database set up in production, and then you've set the correct authentication details in config/database.yml

I ran
heroku run rails console

that gave me a much better understanding of what was wrong. Turns out I had an unexpected end in my users controller...

heroku run rails console
Running `rails console` attached to terminal... up, run.6073
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-  
4.0.2/lib/active_support/dependencies.rb:229:in `require':     
/app/app/controllers/users_controller.rb:68: syntax error, unexpected keyword_end, 
expecting    end-of-input (SyntaxError)

This is an old post, but if you get apps crashing in heroku with no reason/H10 error code on logs, ensure you are using Puma. I faced the same with nothing working but adding Puma to fix it. Basically:

  1. Add Puma to your Gemfile:

     gem 'puma' 
  2. Set Puma as the server for your web process in the Procfile:

     web: bundle exec puma -C config/puma.rb 
  3. Create a configuration file for Puma at config/puma.rb . Heroku recommends the following, but customize for your needs

     workers Integer(ENV['WEB_CONCURRENCY'] || 2) threads_count = Integer(ENV['MAX_THREADS'] || 5) threads threads_count, threads_count<br/> preload_app!<br/> rackup DefaultRackup<br/> port ENV['PORT'] || 3000 environment ENV['RACK_ENV'] || 'development'<br/> on_worker_boot do ActiveRecord::Base.establish_connection end 

More information can be found at heroku.com: Deploying Rails Applications with the Puma Web Server .

I had the same problem, and I spend really a lot of time as beginner to Ruby on Rails, to find the solution. Thanks to Shyam Bhimani who gave it to me on this link . Anyway, the solution is like the following:

NB: you should be inside front your SSH screen, inside your application folder. Now type the following :

$ bundle update 

$ heroku run rake db:migrate

$ heroku run rake db:schema:load

$ git init

$ git add .

$ git commit -am "some comment"

$ git push heroku master

$ git push heroku master

$ heroku open

I was so happy to get my application works on Heroku, and I'm wrting this answer, to help you as Shayam helped me. Regards

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM