【问题标题】:Rails Deployment to Heroku Is Showing ErrorRails 部署到 Heroku 显示错误
【发布时间】:2016-07-03 04:59:43
【问题描述】:

我是新手 需要帮助说明我部署到heroku有什么问题。 这是heroku上的测试链接点击https://stableform4.herokuapp.com/ 问题是:

  1. 我可以登录,但无法创建注册。
  2. “客户端新表单”复选框缺失
  3. 当我点击“提交”时,它显示“我很抱歉,但出了点问题”

我不知道如何解决这个问题,请问有人可以帮我解决这个问题吗?

这是我的 gemfile:

source 'https://rubygems.org'

ruby '2.3.0'
gem 'rails', '4.2.5'

gem 'sass-rails', '~> 5.0'
gem 'bootstrap-sass', '~> 3.3', '>= 3.3.6'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'will_paginate', '3.0.7'
gem 'bootstrap-will_paginate', '0.0.10'
gem 'bcrypt', '3.1.7'


group :development, :test do
  gem 'byebug'
  gem 'pry'
  
end

group :development do
  gem 'web-console', '~> 2.0'
  gem 'spring'
  gem 'sqlite3'
end

group :production do
  gem 'pg'
  gem 'rails_12factor'

end

这是我的“heroku 日志”

yoskakomba:~/workspace (master) $ heroku logs
2016-03-17T01:59:48.800895+00:00 heroku[web.1]: State changed from starting to up
2016-03-17T01:59:49.109588+00:00 app[web.1]: => Booting WEBrick
2016-03-17T01:59:49.109598+00:00 app[web.1]: => Rails 4.2.5 application starting in production on http://0.0.0.0:37193
2016-03-17T01:59:49.109600+00:00 app[web.1]: => Ctrl-C to shutdown server
2016-03-17T01:59:49.109599+00:00 app[web.1]: => Run `rails server -h` for more startup options
2016-03-17T01:59:49.109601+00:00 app[web.1]: Started GET "/" for 139.193.121.119 at 2016-03-17 01:59:49 +0000
2016-03-17T01:59:49.152469+00:00 app[web.1]: Processing by LoginsController#new as HTML
2016-03-17T01:59:49.164862+00:00 app[web.1]:   Rendered shared/_page_title.html.erb (0.3ms)
2016-03-17T01:59:49.165482+00:00 app[web.1]:   Rendered logins/new.html.erb within layouts/application (2.9ms)
2016-03-17T01:59:49.190211+00:00 app[web.1]:   Client Load (1.2ms)  SELECT  "clients".* FROM "clients" WHERE "clients"."id" = $1 LIMIT 1  [["id", 1]]
2016-03-17T01:59:49.203241+00:00 app[web.1]:   Rendered layouts/_navigation.html.erb (35.4ms)
2016-03-17T01:59:49.204391+00:00 app[web.1]:   Rendered layouts/_messages.html.erb (0.7ms)
2016-03-17T01:59:49.205755+00:00 app[web.1]:   Rendered layouts/_footer.html.erb (0.7ms)
2016-03-17T01:59:49.206024+00:00 app[web.1]: Completed 200 OK in 53ms (Views: 36.1ms | ActiveRecord: 10.7ms)
2016-03-17T01:59:49.207719+00:00 heroku[router]: at=info method=GET path="/" host=stableform4.herokuapp.com request_id=46276eb3-6eaa-4e18-8260-2b51e7c4b709 fwd="139.193.121.119" dyno=web.1 connect=2ms service=104ms status=200 bytes=5248
2016-03-17T01:59:54.692610+00:00 heroku[router]: at=info method=GET path="/logout" host=stableform4.herokuapp.com request_id=91a7fe3b-0fc3-4dc5-a017-3b609a7bae68 fwd="139.193.121.119" dyno=web.1 connect=2ms service=12ms status=302 bytes=1119
2016-03-17T01:59:54.686439+00:00 app[web.1]: Started GET "/logout" for 139.193.121.119 at 2016-03-17 01:59:54 +0000
2016-03-17T01:59:54.689001+00:00 app[web.1]: Processing by LoginsController#destroy as HTML
2016-03-17T01:59:54.689700+00:00 app[web.1]: Redirected to https://stableform4.herokuapp.com/
2016-03-17T01:59:54.690247+00:00 app[web.1]: Completed 302 Found in 1ms (ActiveRecord: 0.0ms)
2016-03-17T01:59:55.215672+00:00 heroku[router]: at=info method=GET path="/" host=stableform4.herokuapp.com request_id=e78735f7-914b-477f-adcc-ce83323db296 fwd="139.193.121.119" dyno=web.1 connect=1ms service=18ms status=200 bytes=4922
2016-03-17T01:59:55.202635+00:00 app[web.1]: Started GET "/" for 139.193.121.119 at 2016-03-17 01:59:55 +0000
2016-03-17T01:59:55.204506+00:00 app[web.1]: Processing by LoginsController#new as HTML
2016-03-17T01:59:55.207610+00:00 app[web.1]:   Rendered shared/_page_title.html.erb (0.3ms)
2016-03-17T01:59:55.208417+00:00 app[web.1]:   Rendered logins/new.html.erb within layouts/application (2.5ms)
2016-03-17T01:59:55.211095+00:00 app[web.1]:   Rendered layouts/_navigation.html.erb (1.5ms)
2016-03-17T01:59:55.212567+00:00 app[web.1]:   Rendered layouts/_messages.html.erb (0.4ms)
2016-03-17T01:59:55.213291+00:00 app[web.1]:   Rendered layouts/_footer.html.erb (0.3ms)
2016-03-17T01:59:55.213486+00:00 app[web.1]: Completed 200 OK in 9ms (Views: 8.2ms | ActiveRecord: 0.0ms)
2016-03-17T02:02:09.647931+00:00 heroku[api]: Starting process with command `bundle exec rake db:migrate` by ariel.kakomba@gmail.com
2016-03-17T02:02:12.807089+00:00 heroku[run.1529]: Awaiting client
2016-03-17T02:02:12.841273+00:00 heroku[run.1529]: Starting process with command `bundle exec rake db:migrate`
2016-03-17T02:02:13.097509+00:00 heroku[run.1529]: State changed from starting to up
2016-03-17T02:02:22.198991+00:00 heroku[run.1529]: Process exited with status 0
2016-03-17T02:02:22.214176+00:00 heroku[run.1529]: State changed from up to complete
2016-03-17T02:04:00.656899+00:00 heroku[router]: at=info method=GET path="/" host=stableform4.herokuapp.com request_id=a18b4e0e-4970-4811-9bf4-f0d8f62e0f63 fwd="139.193.121.119" dyno=web.1 connect=0ms service=13ms status=200 bytes=4604
2016-03-17T02:04:00.648236+00:00 app[web.1]: Started GET "/" for 139.193.121.119 at 2016-03-17 02:04:00 +0000
2016-03-17T02:04:00.650631+00:00 app[web.1]: Processing by LoginsController#new as HTML
2016-03-17T02:04:00.653352+00:00 app[web.1]:   Rendered logins/new.html.erb within layouts/application (1.2ms)
2016-03-17T02:04:00.655566+00:00 app[web.1]:   Rendered layouts/_messages.html.erb (0.1ms)
2016-03-17T02:04:00.652335+00:00 app[web.1]:   Rendered shared/_page_title.html.erb (0.0ms)
2016-03-17T02:04:00.655364+00:00 app[web.1]:   Rendered layouts/_navigation.html.erb (0.6ms)
2016-03-17T02:04:00.656716+00:00 app[web.1]: Completed 200 OK in 6ms (Views: 4.6ms | ActiveRecord: 0.0ms)
2016-03-17T02:04:00.656386+00:00 app[web.1]:   Rendered layouts/_footer.html.erb (0.1ms)
2016-03-17T02:04:08.275043+00:00 heroku[router]: at=info method=POST path="/login" host=stableform4.herokuapp.com request_id=c71dfcb4-465c-4070-aea7-59a572158f7d fwd="139.193.121.119" dyno=web.1 connect=0ms service=91ms status=302 bytes=1058
2016-03-17T02:04:08.193729+00:00 app[web.1]: Started POST "/login" for 139.193.121.119 at 2016-03-17 02:04:08 +0000
2016-03-17T02:04:08.196792+00:00 app[web.1]: Processing by LoginsController#create as HTML
2016-03-17T02:04:08.201807+00:00 app[web.1]:   Client Load (1.3ms)  SELECT  "clients".* FROM "clients" WHERE "clients"."email" = $1 LIMIT 1  [["email", "ariel.kakomba@gmail.com"]]
2016-03-17T02:04:08.196833+00:00 app[web.1]:   Parameters: {"utf8"=>"✓", "authenticity_token"=>"u9z0gLOM4sUnz3avEKbr0w6FIkl10mkyInOmB/Dlg6C3ZTJVnWWvdAeRA/Czs/8/ppzy58zoC6kX10mMQofhrA==", "email"=>"ariel.kakomba@gmail.com", "password"=>"[FILTERED]", "commit"=>"Login"}
2016-03-17T02:04:08.274341+00:00 app[web.1]: Completed 302 Found in 77ms (ActiveRecord: 1.3ms)
2016-03-17T02:04:08.273787+00:00 app[web.1]: Redirected to https://stableform4.herokuapp.com/enrollments
2016-03-17T02:04:08.577769+00:00 heroku[router]: at=info method=GET path="/enrollments" host=stableform4.herokuapp.com request_id=b97a0fa7-cee7-4533-a1a8-7dec6323bc90 fwd="139.193.121.119" dyno=web.1 connect=0ms service=15ms status=302 bytes=1226
2016-03-17T02:04:08.568413+00:00 app[web.1]: Started GET "/enrollments" for 139.193.121.119 at 2016-03-17 02:04:08 +0000
2016-03-17T02:04:08.572131+00:00 app[web.1]: Processing by EnrollmentsController#index as HTML
2016-03-17T02:04:08.575119+00:00 app[web.1]:   Client Load (1.2ms)  SELECT  "clients".* FROM "clients" WHERE "clients"."id" = $1 LIMIT 1  [["id", 1]]
2016-03-17T02:04:08.576385+00:00 app[web.1]: Redirected to https://stableform4.herokuapp.com/clients/1
2016-03-17T02:04:08.576653+00:00 app[web.1]: Completed 302 Found in 4ms (ActiveRecord: 1.2ms)
2016-03-17T02:04:08.576503+00:00 app[web.1]: Filter chain halted as :authorize_admin rendered or redirected
2016-03-17T02:04:08.895391+00:00 heroku[router]: at=info method=GET path="/clients/1" host=stableform4.herokuapp.com request_id=26b63272-8010-4409-90a1-7f8ee71ca1f2 fwd="139.193.121.119" dyno=web.1 connect=0ms service=51ms status=200 bytes=5293
2016-03-17T02:04:08.848743+00:00 app[web.1]: Started GET "/clients/1" for 139.193.121.119 at 2016-03-17 02:04:08 +0000
2016-03-17T02:04:08.893270+00:00 app[web.1]:   Rendered layouts/_navigation.html.erb (2.6ms)
2016-03-17T02:04:08.851602+00:00 app[web.1]: Processing by ClientsController#show as HTML
2016-03-17T02:04:08.884658+00:00 app[web.1]:    (1.3ms)  SELECT COUNT(*) FROM "enrollments" WHERE "enrollments"."client_id" = $1  [["client_id", 1]]
2016-03-17T02:04:08.893799+00:00 app[web.1]:   Rendered layouts/_footer.html.erb (0.0ms)
2016-03-17T02:04:08.851684+00:00 app[web.1]:   Parameters: {"id"=>"1"}
2016-03-17T02:04:08.854000+00:00 app[web.1]:   Client Load (1.2ms)  SELECT  "clients".* FROM "clients" WHERE "clients"."id" = $1 LIMIT 1  [["id", 1]]
2016-03-17T02:04:08.879891+00:00 app[web.1]:   Rendered shared/_page_title.html.erb (0.0ms)
2016-03-17T02:04:08.889033+00:00 app[web.1]:   Rendered clients/show.html.erb within layouts/application (10.7ms)
2016-03-17T02:04:08.888057+00:00 app[web.1]:   Enrollment Load (1.2ms)  SELECT  "enrollments".* FROM "enrollments" WHERE "enrollments"."client_id" = $1  ORDER BY "enrollments"."updated_at" DESC LIMIT 3 OFFSET 0  [["client_id", 1]]
2016-03-17T02:04:08.892373+00:00 app[web.1]:   Client Load (1.1ms)  SELECT  "clients".* FROM "clients" WHERE "clients"."id" = $1 LIMIT 1  [["id", 1]]
2016-03-17T02:04:08.893569+00:00 app[web.1]:   Rendered layouts/_messages.html.erb (0.1ms)
2016-03-17T02:04:08.894098+00:00 app[web.1]: Completed 200 OK in 42ms (Views: 16.6ms | ActiveRecord: 6.8ms)
2016-03-17T02:04:13.625835+00:00 app[web.1]: Started GET "/enrollments/new" for 139.193.121.119 at 2016-03-17 02:04:13 +0000
2016-03-17T02:04:13.630925+00:00 app[web.1]: Processing by EnrollmentsController#new as HTML
2016-03-17T02:04:13.697061+00:00 app[web.1]:   Rendered shared/_errors.html.erb (1.2ms)
2016-03-17T02:04:13.635323+00:00 app[web.1]:   Client Load (3.4ms)  SELECT  "clients".* FROM "clients" WHERE "clients"."id" = $1 LIMIT 1  [["id", 1]]
2016-03-17T02:04:13.726775+00:00 app[web.1]:   Reference Load (3.1ms)  SELECT "references".* FROM "references"
2016-03-17T02:04:13.687583+00:00 app[web.1]:   Rendered shared/_page_title.html.erb (0.1ms)
2016-03-17T02:04:13.793988+00:00 app[web.1]:   Rendered layouts/_navigation.html.erb (1.1ms)
2016-03-17T02:04:13.794563+00:00 app[web.1]:   Rendered layouts/_footer.html.erb (0.0ms)
2016-03-17T02:04:13.757761+00:00 app[web.1]:   Body Load (2.9ms)  SELECT "bodies".* FROM "bodies"
2016-03-17T02:04:13.781981+00:00 app[web.1]:   Health Load (6.7ms)  SELECT "healths".* FROM "healths"
2016-03-17T02:04:13.794876+00:00 app[web.1]: Completed 200 OK in 164ms (Views: 78.4ms | ActiveRecord: 40.3ms)
2016-03-17T02:04:13.734171+00:00 app[web.1]:   Preference Load (1.6ms)  SELECT "preferences".* FROM "preferences"
2016-03-17T02:04:13.790775+00:00 app[web.1]:   Rendered enrollments/new.html.erb within layouts/application (104.7ms)
2016-03-17T02:04:13.790668+00:00 app[web.1]:   Rendered enrollments/_form.html.erb (101.6ms)
2016-03-17T02:04:13.794329+00:00 app[web.1]:   Rendered layouts/_messages.html.erb (0.2ms)
2016-03-17T02:04:13.796363+00:00 heroku[router]: at=info method=GET path="/enrollments/new" host=stableform4.herokuapp.com request_id=f969711c-1377-46e0-9f8f-a938fe9abe3a fwd="139.193.121.119" dyno=web.1 connect=0ms service=181ms status=200 bytes=11068
2016-03-17T02:05:43.220836+00:00 heroku[router]: at=info method=POST path="/enrollments" host=stableform4.herokuapp.com request_id=ffb38afc-19bf-4860-b470-d45d7dd390dc fwd="139.193.121.119" dyno=web.1 connect=1ms service=32ms status=500 bytes=1754
2016-03-17T02:05:43.194475+00:00 app[web.1]: Started POST "/enrollments" for 139.193.121.119 at 2016-03-17 02:05:43 +0000
2016-03-17T02:05:43.196504+00:00 app[web.1]: Processing by EnrollmentsController#create as HTML
2016-03-17T02:05:43.196594+00:00 app[web.1]:   Parameters: {"utf8"=>"✓", "authenticity_token"=>"1QcLKJHSbPsEOKCrUFQgK4Tg/sQat8yADgiwyabhvZDZvs39vzshSiRm1fTzQTTHLPkuaqONrhs7rF9CFIPfnA==", "enrollment"=>{"name"=>"Yosafat", "last_name"=>"Kakomba", "dob"=>"06/08/1982", "suburb"=>"Bekasi", "address"=>"Perum Vila Nusa Indah 2 Blok CC2/18 Jatiasih", "telephone"=>"622182403788", "post_code"=>"16969", "occupation"=>"", "exercise"=>"Never", "private_health_fund"=>"", "newsletter"=>"yes", "reference_ids"=>[""], "my_friend"=>"Yosafat Kakomba", "preference_ids"=>[""], "body_ids"=>[""], "health_ids"=>[""], "past_medical_history"=>"", "medication"=>"", "symptoms"=>"", "terms"=>"1"}, "commit"=>"Submit"}
2016-03-17T02:05:43.198509+00:00 app[web.1]:   Client Load (1.2ms)  SELECT  "clients".* FROM "clients" WHERE "clients"."id" = $1 LIMIT 1  [["id", 1]]
2016-03-17T02:05:43.217145+00:00 app[web.1]:    (1.0ms)  BEGIN
2016-03-17T02:05:43.221040+00:00 app[web.1]:    (1.0ms)  ROLLBACK
2016-03-17T02:05:43.221405+00:00 app[web.1]: Completed 500 Internal Server Error in 25ms (ActiveRecord: 8.5ms)
2016-03-17T02:05:43.222225+00:00 app[web.1]: 
2016-03-17T02:05:43.222234+00:00 app[web.1]: RangeError (622182403788 is out of range for ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Integer with limit 4):
2016-03-17T02:05:43.222235+00:00 app[web.1]:   app/controllers/enrollments_controller.rb:25:in `create'
2016-03-17T02:05:43.222258+00:00 app[web.1]: 
2016-03-17T02:05:43.222259+00:00 app[web.1]: 

非常感谢您的帮助

【问题讨论】:

    标签: ruby-on-rails-4 heroku deployment


    【解决方案1】:

    为我工作:


    错误:

    RangeError (622182403788 is out of range for ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Integer with limit 4):
    2016-03-17T02:05:43.222235+00:00 app[web.1]:   app/controllers/enrollments_controller.rb:25:in `create'
    2016-03-17T02:05:43.222258+00:00 app[web.1]: 
    

    这意味着您尝试将整数(数字)622182403788 插入到仅允许 4 数字的 int 列中。

    看起来错误是由您的telephone 输入引起的:

    "telephone"=>"622182403788"
    

    解决方案是telephone 列的increase the limit,或者将telephone 输入限制为4 个数字。


    在处理 Heroku 时,您应该考虑以下几点:

    1. 使用WEBrick 的替代服务器 -- We use Puma 在生产中但没有大量流量。我们的老开发者使用Unicorn,两者都提供并发。

    如果您使用puma,如果您使用 Windows 开发应用程序,最新版本会出现错误。我们的Procfile如下:

    # Procfile
    web: bundle exec puma -C config/puma.rb
    
    #config/puma.rb
    ########################################
    
    ####################
    #       Puma       #
    ####################
    
    ########################################
    
    # https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#adding-puma-to-your-application
    
    if !ENV['RACK_ENV'] || ENV['RACK_ENV'] != 'development' #-> fixes "SIGTERM" error in Windows
        workers Integer(ENV['WEB_CONCURRENCY'] || 2)
        threads_count = Integer(ENV['MAX_THREADS'] || 5)
        threads threads_count, threads_count
    end
    
    preload_app!
    
    rackup      DefaultRackup
    port        ENV['PORT']     || 3000
    environment ENV['RACK_ENV'] || 'development'
    
    on_worker_boot do
      # Worker specific setup for Rails 4.1+
      # See: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#on-worker-boot
      ActiveRecord::Base.establish_connection
    end
    
    ########################################
    
    1. Heroku 的日志是你最好的朋友 - 翻阅日志会告诉你到底发生了什么

    2. 使用“异常”gem——替换 Rails 标准错误页面。我们开发了exception_handler 来实现这一点,并且现在非常很受欢迎:

    您只需将其添加到您的Gemfile,您就可以访问生产中的整个异常消息/详细信息:

    #Gemfile
    gem "exception_handler"
    

    它是完全可定制的,我们已经在 Heroku 上对其进行了彻底的测试——它适用于 Rails 4 和 5。

    与标准的“出现问题”错误相比,它应该为您提供更多的工作。


    更新

    在我看来,您的 Reference 模型/表中没有任何记录。

    原因是Heroku 意味着 是与您的开发系统不同的“环境”。因此,数据库应该是完全独立的。

    您可以阅读有关setting up your databases in different environments here 的更多信息。

    -

    需要考虑的重要一点是,由于您使用的是不同 数据库,您的production 数据库中不会有任何数据。

    你可以通过打开heroku console来测试这个:

    # heroku run rails console
    # refs = Reference.all
    # -> should output all "Reference" records / objects
    

    如果上述没有显示任何对象,您将不得不填充它们。有两种方法可以做到这一点:

    • 手动将它们添加到系统中
    • rake db:seed

    如果您不介意保留data integrity,您可以保持console 会话打开,并使用以下内容创建一些记录:

    # Reference.create attribute: "value", attribute_2: "value"
    

    这将为您手动创建记录。

    执行此操作的“正确”方法是"seed" the database:

    # db/seeds.rb
    Reference.create name: "value", description: "value"
    

    这将允许您从 heroku 控制台运行 rake db:seed

    # heroku run rails console
    # rake db:seed
    

    【讨论】:

    • 感谢 Richard 的帮助,我将应用它来修复错误。如何解决表单中的“复选框”在部署到 Heroku 时丢失但在 c9.io 中可以看到“复选框”的问题。 imgur.com/tG4IzGM
    • 这些复选框是使用fields_for构建的吗?
    • 我正在将此代码用于复选框:'参考:
      ' 非常感谢您的帮助跨度>
    • 您的代码看起来不错——最大的考验是,您的Reference 模型/表格中有什么内容?请记住,在使用 Heroku 时,您的数据会在您使用“生产”数据库时被完全擦除。
    • Heroku中是否有缺失如何检查,如何解决?是去 Heroku run rails console 和 model.all 吗?如果我发现缺少的东西如何正确地放入数据库?非常感谢您的帮助
    猜你喜欢
    • 2011-09-07
    • 2018-05-08
    • 1970-01-01
    • 1970-01-01
    • 2013-05-25
    • 1970-01-01
    • 1970-01-01
    • 2014-08-04
    • 1970-01-01
    相关资源
    最近更新 更多