如何修复此问题以将Rails应用程序部署到Heroku?

时间:2015-05-20 12:48:36

标签: ruby-on-rails heroku

当我运行'heroku local'时,一切正常!

但是,当我运行'heroku open'时,它不起作用:

  

“您要查找的页面不存在。您可能输入错误   地址或页面可能已移动。如果你是申请人   所有者检查日志以获取更多信息。“

这是我的Gemfile:

source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
ruby '2.2.1'
gem 'rails', '4.0.2'
gem 'puma'
gem 'foreman'

# Use postgresql as the database for Active Record
gem 'pg'

# Use SCSS for stylesheets
gem 'sass-rails', '5.0.2'

# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'

# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'

# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'

group :doc do
  # bundle exec rake doc:rails generates the API under doc/api.
  gem 'sdoc', require: false
end

这是Procfile:

web: bundle exec puma -e  -p 5000 -S ~/puma -C config/puma.rb

这是文件日志:

2015-05-20T12:38:42.297654+00:00 app[web.1]: Started GET "/" for 183.81.86.77 at 2015-05-20 12:38:42 +0000
2015-05-20T12:38:42.392427+00:00 app[web.1]: 
2015-05-20T12:38:42.392433+00:00 app[web.1]: ActionController::RoutingError (No route matches [GET] "/"):
2015-05-20T12:38:42.392437+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/actionpack-4.0.2/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
2015-05-20T12:38:42.392445+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/activesupport-4.0.2/lib/active_support/tagged_logging.rb:67:in `tagged'
2015-05-20T12:38:42.392435+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/actionpack-4.0.2/lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
2015-05-20T12:38:42.392452+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/actionpack-4.0.2/lib/action_dispatch/middleware/request_id.rb:21:in `call'
2015-05-20T12:38:42.392456+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/activesupport-4.0.2/lib/active_support/cache/strategy/local_cache.rb:83:in `call'
2015-05-20T12:38:42.392439+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/railties-4.0.2/lib/rails/rack/logger.rb:38:in `call_app'
2015-05-20T12:38:42.392440+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/railties-4.0.2/lib/rails/rack/logger.rb:20:in `block in call'
2015-05-20T12:38:42.392458+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/actionpack-4.0.2/lib/action_dispatch/middleware/static.rb:64:in `call'
2015-05-20T12:38:42.392459+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/rack-1.5.2/lib/rack/sendfile.rb:112:in `call'
2015-05-20T12:38:42.392461+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/railties-4.0.2/lib/rails/engine.rb:511:in `call'
2015-05-20T12:38:42.392462+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/railties-4.0.2/lib/rails/application.rb:97:in `call'
2015-05-20T12:38:42.392463+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/puma-2.11.1/lib/puma/configuration.rb:82:in `call'
2015-05-20T12:38:42.392442+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/activesupport-4.0.2/lib/active_support/tagged_logging.rb:67:in `block in tagged'
2015-05-20T12:38:42.392443+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/activesupport-4.0.2/lib/active_support/tagged_logging.rb:25:in `tagged'
2015-05-20T12:38:42.392466+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/puma-2.11.1/lib/puma/server.rb:375:in `process_client'
2015-05-20T12:38:42.392467+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/puma-2.11.1/lib/puma/server.rb:262:in `block in run'
2015-05-20T12:38:42.392455+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/rack-1.5.2/lib/rack/runtime.rb:17:in `call'
2015-05-20T12:38:42.392453+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in `call'
2015-05-20T12:38:42.392450+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/railties-4.0.2/lib/rails/rack/logger.rb:20:in `call'
2015-05-20T12:38:42.392468+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/puma-2.11.1/lib/puma/thread_pool.rb:104:in `call'
2015-05-20T12:38:42.392470+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/puma-2.11.1/lib/puma/thread_pool.rb:104:in `block in spawn_thread'
2015-05-20T12:38:42.392472+00:00 app[web.1]: 
2015-05-20T12:38:42.392464+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/puma-2.11.1/lib/puma/server.rb:507:in `handle_request'
2015-05-20T12:38:42.392471+00:00 app[web.1]: 
2015-05-20T12:38:42.777619+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=bachvanngoc.herokuapp.com request_id=29570c12-9b74-4b70-b109-7365acb4938e fwd="183.81.86.77" dyno=web.1 connect=0ms service=2ms status=200 bytes=143
2015-05-20T12:38:41.882707+00:00 heroku[web.1]: State changed from starting to up
WARNING: Toolbelt v3.37.1 update available.

2 个答案:

答案 0 :(得分:1)

这不是部署问题

从您的Heroku日志中,您似乎没有定义处理根路径的路由。

ActionController::RoutingError (No route matches [GET] "/"):

如果查看config/routes.rb文件,则需要定义控制器/操作来处理该路径。

类似的东西:

root to: "acontroller#anaction"

get "/" => "acontroller#anaction"

开发期间的Rails在根路径上提供默认页面。如果您在生产环境中运行rails应用程序,则不会显示此默认页面。您可以通过rails server -e production在本地查看此信息,但您会注意到您没有获得相同的主页,但是您在Heroku中获得的页面相同。

答案 1 :(得分:0)

您应该在项目路径中,并运行:

heroku run rake db:create

heroku run db:migrate

同时运行

heroku --help

了解更多信息。