Rails部署到Heroku显示错误 [英] Rails Deployment to Heroku Is Showing Error

查看:171
本文介绍了Rails部署到Heroku显示错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新手
需要帮助,请显示我的部署到heroku有什么问题。
这里是英雄测试链接点击






错误:

  RangeError(622182403788超出范围为ActiveRecord :: ConnectionAdapters :: PostgreSQL :: OID :: Integer与限制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 int 列,只允许 4 数位。



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

 code>phone=>622182403788

href =http://stackoverflow.com/questions/32004570/rails-migration-how-to-increase-integer-size-by-using-ror-migration>增加限制电话列的c $ c> ,或限制电话 inpu t到4个数字。






在处理Heroku时,您应该考虑几件事:


  1. 使用替代服务器 WEBrick -







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

      #Gemfile 
    gemexception_handler

    它完全可定制,我们已经在Heroku上彻底测试了它 - 它与Rails 4&



    它应该比标准的发生错误错误更多。






    更新



    听起来像你没有任何记录在你的参考模型/表。



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



    您可以阅读更多关于在不同环境中设置数据库



    -



    要考虑的重要事情是,因为您使用的是不同的数据库,所以您的生产 db将不会其中的任何数据。



    您可以通过打开 heroku控制台

      #heroku run rails console 
    #refs = Reference.all
    # - >应输出所有参考记录/对象

    如果上述没有显示任何对象,你必须填充它们。有两种方法:




    • 手动将其添加到系统中

    • rake db:seed



    如果你不担心保留数据完整性,您将能够保留您的控制台会话打开,并使用以下内容创建一些记录:

     #Reference.create属性:value,attribute_2:value 

    这将为您手动创建记录。



    正确的方法是种子数据库

     #db / seeds.rb 
    Reference.create name:value ,描述:value

    这将允许您运行 rake db:来自英雄控制台的种子

     #heroku run rails console 
    #rake db:seed
    pre>

    I am newbie need help please on showing what's wrong with my deployment to heroku. here is the testing link on heroku click https://stableform4.herokuapp.com/ The problems are:

    1. I can log in but can not create an enrollment.
    2. on 'client new form' checkboxes are missing
    3. When I click 'submit' it says "I am sorry, but something went wrong"

    I don't know what to do to resolve this issue, please, is there anyone can help me solve this issue?

    here is my 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

    here is my 'heroku logs'

    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]: 

    Thank you so much for the help

    解决方案

    Worked for me:


    Error:

    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]: 
    

    This means you're trying you insert an integer (number) of 622182403788 into an int column that only allows 4 digits.

    It looks like the error is caused by your telephone input:

    "telephone"=>"622182403788"
    

    The solution is either to increase the limit of the telephone column, or limit the telephone input to 4 numbers.


    There are several things you should consider when dealing with Heroku:

    1. Use an alternative server to WEBrick -- We use Puma in production but don't have massive traffic. Our old devs used Unicorn, both of which provide concurrency.

    If you use puma, the latest version kicks up errors if you're using Windows to develop the app. Our Procfile is as follows:

    # 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's logs are your best friend - picking through the logs will tell you exactly what happened

    2. Use an "exceptions" gem -- to replace the Rails standard error pages. We've developed exception_handler to do this, and is now extremely popular:

    You just need to add it to your Gemfile and you'll get access to the entire exception message / details in production:

    #Gemfile
    gem "exception_handler"
    

    It's fully customizable and we've tested it thoroughly on Heroku -- it works with Rails 4 & 5.

    It should give you much more to work with than the standard "Something went wrong" error.


    Update

    Sounds to me like you don't have any records in your Reference model / table.

    The reason for this is that Heroku is meant to be a different "environment" than your development system. As such, the database is supposed to be completely separate.

    You can read more about setting up your databases in different environments here.

    -

    The important thing to consider is that because you're using different databases, your production db won't have any data in it.

    You can test this by opening the heroku console:

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

    If the above does not show any objects, you'll have to populate them. There are two ways to do this:

    • manually adding them to the system
    • rake db:seed

    If you're not bothered about retaining data integrity, you'll be able to keep your console session open, and use the following to create some records:

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

    This will create the records manually for you.

    The "correct" way to do this is to "seed" the database:

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

    This will allow you to run rake db:seed from the heroku console:

    # heroku run rails console
    # rake db:seed
    

    这篇关于Rails部署到Heroku显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆