简体   繁体   English

Ruby on Rails网站在本地工作,路线正确,但在heroku上却得到404

[英]Ruby on Rails website worked locally, routes correct, but on heroku get 404

This is a really strange error that I've encountered. 这是我遇到的一个非常奇怪的错误。 I use ruby on rails. 我在轨道上使用红宝石。 Everything works fine locally (on cloud 9) and I successfully pushed it to Heroku. 本地一切正常(在云9上),我成功地将其推送到了Heroku。 I have run db:migrate with no error. 我已经运行db:migrate且没有错误。 Nonetheless, I get error "The page you were looking for doesn't exist" and the log says 404. I have checked the files and they have been correctly uploaded. 但是,我收到错误消息“您要查找的页面不存在”,并且日志显示404。我检查了文件,并已正确上传它们。 My routes: 我的路线:

  root 'application#index'
  get '/index/:type' => 'application#index'
  get '/index/' => 'application#index'
  get '/benchmark/' => 'application#benchmark'
  get '/benchmark/:type' => 'application#benchmark'
  get '/benchmarkupdate/:name' => 'application#benchmark'
  get '/indexupdate/:name' => 'application#index'

I have files in correct locations. 我的文件位置正确。 I don't see any problem with routing and it has worked locally. 我看不到路由有任何问题,并且它在本地工作。

Heroku Logs: Heroku日志:

2017-04-18T03:13:14.455398+00:00 app[web.1]: * Version 3.8.2 (ruby 2.3.4-p301), codename: Sassy Salamander
2017-04-18T03:13:14.455399+00:00 app[web.1]: * Min threads: 5, max threads: 5
2017-04-18T03:13:14.455399+00:00 app[web.1]: * Environment: production
2017-04-18T03:13:15.493228+00:00 app[web.1]: DEPRECATION WARNING: `config.serve_static_files` is deprecated and will be removed in Rails 5.1.
2017-04-18T03:13:15.493241+00:00 app[web.1]: Please use `config.public_file_server.enabled = true` instead.
2017-04-18T03:13:15.493243+00:00 app[web.1]:  (called from block in <top (required)> at /app/config/environments/production.rb:25)
2017-04-18T03:13:16.337785+00:00 app[web.1]: * Listening on tcp://0.0.0.0:49146
2017-04-18T03:13:16.337997+00:00 app[web.1]: Use Ctrl-C to stop
2017-04-18T03:13:16.847301+00:00 heroku[web.1]: State changed from starting to up
2017-04-18T03:13:18.094441+00:00 heroku[router]: at=info method=GET path="/" host=protected-coast-54392.herokuapp.com request_id=3d8c7a3f-3f40-4747-862f-7e70e7c9029e fwd="152.3.34.25" dyno=web.1 connect=1ms service=75ms status=404 bytes=1744 protocol=https

Is there anything else that might cause this problem? 还有什么可能导致此问题的吗?

The problem is you haven't set a root route meaning when someone goes to www.example.com without any path after it they are going to the root route. 问题是您没有设置根路由,这意味着当某人进入www.example.com之后却没有任何路径时,他们将进入根路由。 In your routes file add something like 在您的路线文件中添加类似

root 'application#index'

or whatever controller and action and the corresponding view that you want people to go to when they first visit your site. 或您希望人们首次访问您的网站时要使用的控制器和操作以及相应的视图。

Well, for one thing you should not be running WEBrick on production. 好吧,一方面,您不应该在生产环境中运行WEBrick。 I'm not positive if this is causing your error, but I'd start there. 如果这引起您的错误,我并不乐观,但我将从这里开始。

Heroku currently recommends puma . Heroku目前推荐puma

You can install puma by including it in your Gemfile as gem 'puma' and then running bundle install. 您可以通过将puma作为Gemfile gem 'puma'包含在Gemfile来安装puma,然后运行捆绑安装。

In your project directory you will need to include a Procfile that tells your app how to run its web server. 在项目目录中,您将需要包含一个Procfile ,以告诉您的应用程序如何运行其Web服务器。

Make sure the Procfile is properly capitalized and checked into git. 确保Procfile正确大写并检入git。

It should look something like this: 它看起来应该像这样:

# <Rails.root>/Procfile
web: bundle exec puma -t 5:5 -p ${PORT:-3000} -e ${RACK_ENV:-development}

Here's an article about WEBrick and one on how to set up puma . 这是一篇关于WEBrick的文章,也是一篇关于如何设置puma的文章

You'll need to re-push to heroku. 您需要重新推送到heroku。 See if that helps. 看看是否有帮助。 Cheers. 干杯。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM