Ruby on Rails 网站在本地运行,路由正确,但在 heroku 上得到 404 [英] Ruby on Rails website worked locally, routes correct, but on heroku get 404
问题描述
这是我遇到的一个非常奇怪的错误.我在导轨上使用红宝石.在本地(在云 9 上)一切正常,我成功地将它推送到 Heroku.我已经运行 db:migrate 没有错误.尽管如此,我收到错误消息您要查找的页面不存在"并且日志显示 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. I have run db:migrate with no error. 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. 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 日志:
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?
推荐答案
问题是你没有设置根路由,意思是当有人在没有任何路径的情况下访问 www.example.com 之后他们将转到根路由.在你的路由文件中添加类似
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. 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.
这篇关于Ruby on Rails 网站在本地运行,路由正确,但在 heroku 上得到 404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!