我已经开始了迈克尔哈特尔的Rails教程,并且对所有这些都是新手。一切都很顺利,直到我到达第2章的末尾。这仍然有效:
$ git status
$ git add -A
$ git commit -m "Finish toy app"
$ git push
$ git push heroku
虽然发布到Heroku也没有生成错误消息,但当我在线访问该页面时,我收到错误消息:
Application 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.
您可以在终端找到包括日志的内容。有谁知道导致问题的原因是什么?
username@rails-tutorial:~/workspace/toy_app (master) $ heroku run rake db:migrate
Running `rake db:migrate` attached to terminal... up, run.3711
ActiveRecord::SchemaMigration Load (2.8ms) SELECT "schema_migrations".* FROM "schema_migrations"
username@rails-tutorial:~/workspace/toy_app (master) $ heroku logs
2015-03-16T16:12:14.228371+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
2015-03-16T16:12:14.228375+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/commands.rb:17:in `<top (required)>'
2015-03-16T16:12:15.133387+00:00 heroku[web.1]: Process exited with status 1
2015-03-16T16:12:15.150260+00:00 heroku[web.1]: State changed from starting to crashed
2015-03-16T16:12:23.823438+00:00 heroku[web.1]: State changed from crashed to starting
2015-03-16T16:12:27.761846+00:00 heroku[web.1]: Starting process with command `bin/rails server -p 22674 -e production`
2015-03-16T16:12:32.166443+00:00 app[web.1]: => Booting WEBrick
2015-03-16T16:12:32.166462+00:00 app[web.1]: => Rails 4.2.0 application starting in production on http://0.0.0.0:22674
2015-03-16T16:12:32.166465+00:00 app[web.1]: => Run `rails server -h` for more startup options
2015-03-16T16:12:32.166466+00:00 app[web.1]: => Ctrl-C to shutdown server
2015-03-16T16:12:32.166469+00:00 app[web.1]: Exiting
2015-03-16T16:12:32.167270+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/activemodel-4.2.0/lib/active_model/validations/length.rb:28:in `check_validity!': Range unspecified. Specify the :in, :within, :maximum, :minimum, or :is option. (ArgumentError)
2015-03-16T16:12:32.167275+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/activemodel-4.2.0/lib/active_model/validator.rb:141:in `initialize'
2015-03-16T16:12:32.167279+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/activemodel-4.2.0/lib/active_model/validations/length.rb:21:in `initialize'
2015-03-16T16:12:32.167282+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/activemodel-4.2.0/lib/active_model/validations/with.rb:92:in `new'
2015-03-16T16:12:32.167286+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/activemodel-4.2.0/lib/active_model/validations/with.rb:92:in `block in validates_with'
2015-03-16T16:12:32.167290+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/activemodel-4.2.0/lib/active_model/validations/with.rb:91:in `each'
2015-03-16T16:12:32.167293+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/activemodel-4.2.0/lib/active_model/validations/with.rb:91:in `validates_with'
2015-03-16T16:12:32.167295+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/activemodel-4.2.0/lib/active_model/validations/length.rb:120:in `validates_length_of'
2015-03-16T16:12:32.167299+00:00 app[web.1]: from /app/app/models/micropost.rb:3:in `<class:Micropost>'
2015-03-16T16:12:32.167302+00:00 app[web.1]: from /app/app/models/micropost.rb:1:in `<top (required)>'
2015-03-16T16:12:32.167306+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
2015-03-16T16:12:32.167310+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `block in require'
2015-03-16T16:12:32.167311+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency'
2015-03-16T16:12:32.167314+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
2015-03-16T16:12:32.167319+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:360:in `require_or_load'
2015-03-16T16:12:32.167320+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:317:in `depend_on'
2015-03-16T16:12:32.167324+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:233:in `require_dependency'
2015-03-16T16:12:32.167328+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/engine.rb:472:in `block (2 levels) in eager_load!'
2015-03-16T16:12:32.167329+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/engine.rb:471:in `each'
2015-03-16T16:12:32.167333+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/engine.rb:471:in `block in eager_load!'
2015-03-16T16:12:32.167336+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/engine.rb:469:in `each'
2015-03-16T16:12:32.167349+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/initializable.rb:30:in `instance_exec'
2015-03-16T16:12:32.167353+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/initializable.rb:30:in `run'
2015-03-16T16:12:32.167354+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/initializable.rb:55:in `block in run_initializers'
2015-03-16T16:12:32.167371+00:00 app[web.1]: from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:150:in `block in tsort_each'
2015-03-16T16:12:32.167372+00:00 app[web.1]: from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:183:in `block (2 levels) in each_strongly_connected_component'
2015-03-16T16:12:32.167374+00:00 app[web.1]: from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:219:in `each_strongly_connected_component_from'
2015-03-16T16:12:32.167376+00:00 app[web.1]: from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:182:in `block in each_strongly_connected_component'
2015-03-16T16:12:32.167377+00:00 app[web.1]: from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:180:in `each'
2015-03-16T16:12:32.167379+00:00 app[web.1]: from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:180:in `each_strongly_connected_component'
2015-03-16T16:12:32.167345+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/application/finisher.rb:56:in `each'
2015-03-16T16:12:32.167346+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/application/finisher.rb:56:in `block in <module:Finisher>'
2015-03-16T16:12:32.167383+00:00 app[web.1]: from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:148:in `tsort_each'
2015-03-16T16:12:32.167384+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/initializable.rb:54:in `run_initializers'
2015-03-16T16:12:32.167386+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/application.rb:352:in `initialize!'
2015-03-16T16:12:32.167387+00:00 app[web.1]: from /app/config/environment.rb:5:in `<top (required)>'
2015-03-16T16:12:32.167389+00:00 app[web.1]: from /app/config.ru:3:in `require'
2015-03-16T16:12:32.167392+00:00 app[web.1]: from /app/config.ru:3:in `block in <main>'
2015-03-16T16:12:32.167393+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/rack-1.6.0/lib/rack/builder.rb:55:in `instance_eval'
2015-03-16T16:12:32.167338+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/engine.rb:469:in `eager_load!'
2015-03-16T16:12:32.167341+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/engine.rb:346:in `eager_load!'
2015-03-16T16:12:32.167395+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/rack-1.6.0/lib/rack/builder.rb:55:in `initialize'
2015-03-16T16:12:32.167399+00:00 app[web.1]: from /app/config.ru:in `new'
2015-03-16T16:12:32.167400+00:00 app[web.1]: from /app/config.ru:in `<main>'
2015-03-16T16:12:32.167403+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/rack-1.6.0/lib/rack/builder.rb:49:in `eval'
2015-03-16T16:12:32.167405+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/rack-1.6.0/lib/rack/builder.rb:49:in `new_from_string'
2015-03-16T16:12:32.167408+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/rack-1.6.0/lib/rack/builder.rb:40:in `parse_file'
2015-03-16T16:12:32.167410+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/rack-1.6.0/lib/rack/server.rb:299:in `build_app_and_options_from_config'
2015-03-16T16:12:32.167413+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/rack-1.6.0/lib/rack/server.rb:208:in `app'
2015-03-16T16:12:32.167415+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/commands/server.rb:61:in `app'
2015-03-16T16:12:32.167418+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/rack-1.6.0/lib/rack/server.rb:336:in `wrapped_app'
2015-03-16T16:12:32.167419+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/rack-1.6.0/lib/rack/server.rb:272:in `start'
2015-03-16T16:12:32.167424+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/commands/server.rb:80:in `start'
2015-03-16T16:12:32.167430+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:80:in `block in server'
2015-03-16T16:12:32.167432+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:75:in `tap'
2015-03-16T16:12:32.167438+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:75:in `server'
2015-03-16T16:12:32.167494+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
2015-03-16T16:12:32.167497+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/commands.rb:17:in `<top (required)>'
2015-03-16T16:12:32.167503+00:00 app[web.1]: from bin/rails:8:in `require'
2015-03-16T16:12:32.167505+00:00 app[web.1]: from bin/rails:8:in `<main>'
2015-03-16T16:12:33.038637+00:00 heroku[web.1]: State changed from starting to crashed
2015-03-16T16:12:33.014202+00:00 heroku[web.1]: Process exited with status 1
2015-03-16T16:12:57.029564+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=gentle-gorge-8333.herokuapp.com request_id=b76e9671-28e6-462f-9929-0775bf8c0434 fwd="myIPaddress" dyno= connect= service= status=503 bytes=
2015-03-16T16:13:59.660339+00:00 heroku[api]: Starting process with command `bin/rails console` by myemail@gmail.com
2015-03-16T16:14:03.167889+00:00 heroku[run.6799]: Awaiting client
2015-03-16T16:14:03.229126+00:00 heroku[run.6799]: Starting process with command `bin/rails console`
2015-03-16T16:14:03.466452+00:00 heroku[run.6799]: State changed from starting to up
2015-03-16T16:14:07.621983+00:00 heroku[run.6799]: State changed from up to complete
2015-03-16T16:14:07.608134+00:00 heroku[run.6799]: Process exited with status 1
2015-03-16T16:14:21.902018+00:00 heroku[api]: Starting process with command `bin/rails console` by myemail@gmail.com
2015-03-16T16:14:25.820558+00:00 heroku[run.8812]: Awaiting client
2015-03-16T16:14:25.849196+00:00 heroku[run.8812]: Starting process with command `bin/rails console`
2015-03-16T16:14:26.218227+00:00 heroku[run.8812]: State changed from starting to up
2015-03-16T16:14:31.553873+00:00 heroku[run.8812]: Process exited with status 1
2015-03-16T16:14:31.564270+00:00 heroku[run.8812]: State changed from up to complete
2015-03-16T16:14:42.838651+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=gentle-gorge-8333.herokuapp.com request_id=2b2ce876-5599-42f9-8c27-3e21d2edb411 fwd="myIPaddress" dyno= connect= service= status=503 bytes=
2015-03-16T16:14:51.861982+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=gentle-gorge-8333.herokuapp.com request_id=b91fd11a-4e0f-4f0f-a372-87a2b5982a64 fwd="myIPaddress" dyno= connect= service= status=503 bytes=
2015-03-16T16:14:58.264781+00:00 heroku[api]: Starting process with command `bin/rails console` by myemail@gmail.com
2015-03-16T16:15:03.472248+00:00 heroku[run.2037]: Awaiting client
2015-03-16T16:15:03.540189+00:00 heroku[run.2037]: Starting process with command `bin/rails console`
2015-03-16T16:15:03.670255+00:00 heroku[run.2037]: State changed from starting to up
2015-03-16T16:15:08.597910+00:00 heroku[run.2037]: State changed from up to complete
2015-03-16T16:15:08.584585+00:00 heroku[run.2037]: Process exited with status 1
2015-03-16T16:18:46.566771+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=gentle-gorge-8333.herokuapp.com request_id=8c130bd4-2fc8-4194-8347-bf84946ae43c fwd="myIPaddress" dyno= connect= service= status=503 bytes=
2015-03-16T16:30:14.169700+00:00 heroku[api]: Starting process with command `bundle exec rake db:migrate` by myemail@gmail.com
2015-03-16T16:30:18.052771+00:00 heroku[run.3711]: Awaiting client
2015-03-16T16:30:18.088848+00:00 heroku[run.3711]: Starting process with command `bundle exec rake db:migrate`
2015-03-16T16:30:18.409372+00:00 heroku[run.3711]: State changed from starting to up
2015-03-16T16:30:23.478003+00:00 heroku[run.3711]: State changed from up to complete
2015-03-16T16:30:23.465440+00:00 heroku[run.3711]: Process exited with status 0
Went to https://gentle-gorge-8333.herokuapp.com/ in my web browser and the error was still there.
username@rails-tutorial:~/workspace/toy_app (master) $ heroku logs
Additional log:
2015-03-16T16:33:34.579254+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=gentle-gorge-8333.herokuapp.com request_id=8df1ee88-9e04-400a-9800-5d169b305c52 fwd="myIPaddress" dyno= connect= service= status=503 bytes=
2015-03-16T16:33:35.468612+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=gentle-gorge-8333.herokuapp.com request_id=e42ae3ea-641b-4f19-855e-ae77c56cd0eb fwd="myIPaddress" dyno= connect= service= status=503 bytes=
2015-03-16T16:33:35.347321+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=gentle-gorge-8333.herokuapp.com request_id=e0a19161-fce3-4cef-a868-2bff28010e8b fwd="myIPaddress" dyno= connect= service= status=503 bytes=
答案 0 :(得分:1)
您似乎将教程的语法与另一个验证器混合在了一起。本教程使用的是validates
,您正在使用validates_length_of
。
正确的语法是validates :content, length: { maximum: 140 }
或validates_length_of :content, maximum: 140
(来自here)
至少就目前而言,我仍然坚持使用教程的语法。