简体   繁体   English

Rails应用程序在本地运行,但在部署到Heroku时则不行

[英]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. 我部署到heroku并收到应用程序错误。 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 heroku日志

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 的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. 在必须部署到heroku之后,需要在开始工作之前运行rake db:migrate。 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. 这应该可以解决您遇到的503错误。

There are two types of error of Rails apps on Heroku: Heroku上有两种类型的Rails应用程序错误:

Heroku Heroku的

在此输入图像描述

This means Heroku has a problem at platform-level (IE Rails cannot be loaded). 这意味着Heroku在平台级别存在问题(无法加载IE Rails)。 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 这通常是一个database问题,可以通过确保创建db或从CMD运行heroku run rake db:migrate命令来解决

-- -

Rails 轨道

在此输入图像描述

This is a Rails specific error, caused when you hit a Rails app which has problems internally . 这是一个Rails特定错误,当您点击内部存在问题的Rails应用程序时会导致该错误。 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 这只会显示整个Heroku平台是否运行良好,这意味着如果你有一个db设置等 - 这意味着代码中的某些内容被破坏


The difference here is that one error is platform specific, whilst the other is application specific. 这里的区别在于,一个错误是特定于platform ,而另一个错误是特定于application 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 )错误,你需要确保你可以解决你在Heroku平台上遇到的任何问题 - 这可以通过以下方式完成:

$ heroku run rake db:migrate

This is, of course, considering you have a database set up for your Rails application. 当然,这是考虑到您为Rails应用程序设置了数据库。 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 如果是这种情况,您需要确保在生产中设置了数据库,然后在config/database.yml设置了正确的身份验证详细信息。

I ran 我跑了
heroku run rails console heroku运行rails控制台

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. 这是一个旧帖子,但是如果你在日志中没有原因/ H10错误代码的情况下使应用程序崩溃,请确保您使用的是Puma。 I faced the same with nothing working but adding Puma to fix it. 我面对同样没有任何工作,但添加Puma来解决它。 Basically: 基本上:

  1. Add Puma to your Gemfile: 将Puma添加到您的Gemfile:

     gem 'puma' 
  2. Set Puma as the server for your web process in the Procfile: 将Puma设置为Procfile中Web进程的服务器:

     web: bundle exec puma -C config/puma.rb 
  3. Create a configuration file for Puma at config/puma.rb . config/puma.rb为Puma创建配置文件。 Heroku recommends the following, but customize for your needs Heroku推荐以下内容,但可根据您的需求进行定制

     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 . 更多信息可以在heroku.com上找到: 使用Puma Web Server部署Rails应用程序

I had the same problem, and I spend really a lot of time as beginner to Ruby on Rails, to find the solution. 我有同样的问题,我花了很多时间作为Ruby on Rails的初学者,找到解决方案。 Thanks to Shyam Bhimani who gave it to me on this link . 感谢Shyam Bhimani在这个链接上给了我。 Anyway, the solution is like the following: 无论如何,解决方案如下:

NB: you should be inside front your SSH screen, inside your application folder. 注意:您应该在应用程序文件夹内的SSH屏幕前面。 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. 我很高兴让我的应用程序在Heroku上工作,而我正在回答这个问题,以帮助你,因为Shayam帮助了我。 Regards 问候

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Rails App可在本地运行,但在Heroku上部署时无法运行 - Rails App works locally but not when deployed on Heroku Rails 4-应用程序可在本地运行,但不能在Heroku上运行 - Rails 4 - App works locally, but not on Heroku &#39;pg&#39;在本地工作,但在部署到Heroku时不行 - 'pg' works locally, but not when deployed to Heroku Heroku:Rails应用程序可在本地运行,但在Heroku上崩溃 - Heroku: Rails app works locally but crashes on heroku Rails应用程序在本地运行,在Heroku上崩溃 - Rails app works locally, crashes on Heroku Rails 应用程序在本地工作,但不适用于 Heroku 的生产环境 - Rails App works locally, but not in production with Heroku Rails App搜索栏可在本地使用,但不能在Heroku上使用 - Rails App search bar works locally but not on Heroku Javascript资产未加载到已部署的Heroku应用(生产)中,但在本地运行良好 - Javascript assets not loading to deployed Heroku app(Production), but works fine locally 通过Heroku部署时,CSS在Safari上中断,但在本地运行良好吗? - CSS breaks on Safari when deployed via Heroku, but works perfectly locally? 在运行时在heroku中发送文本时,Rails Twilio App会挂起,但在heroku(以及所有环境中的本地)的Rail console中可以运行 - Rails Twilio App hangs when sending text in heroku on run, but works in rail console on heroku (and locally in all environments)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM