Ruby-on-rails Heroku 问题:您要查找的页面不存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7376966/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Heroku problem : The page you were looking for doesn't exist
提问by widjajayd
I have followed book until chapter 5 finished and it's working OK in my linux workstation when I push to Heroku, all data pushed correctly but when I try to open Heroku (http://vivid-sky-685.heroku.com)
我一直跟着书直到第 5 章完成,当我推送到 Heroku 时,它在我的 linux 工作站中工作正常,所有数据都正确推送,但是当我尝试打开 Heroku (http://vivid-sky-685.heroku.com)
I get a 404 message.
我收到一条 404 消息。
The page you were looking for doesn't exist. You may have mistyped the address or the page may have moved.
您要找的页面不存在。您可能输入错误的地址或页面可能已移动。
Below is my Gemfilefor application
以下是我Gemfile的申请
source 'http://rubygems.org'
gem 'rails', '3.0.5'
gem 'sqlite3'
group :development do
gem 'rspec-rails', '2.5.0'
end
group :test do
gem 'rspec', '2.5.0'
gem 'webrat', '0.7.1'
gem 'spork', '0.9.0.rc4'
end
gem 'rake','~> 0.8.7'
Any ideas what could be going wrong?
任何想法可能会出错?
@odin here is my heroku logs , thanks
@odin 这是我的 heroku 日志,谢谢
2011-09-11T10:41:57+00:00 heroku[router]: GET vivid-sky-685.heroku.com/y dyno=web.1 queue=0 wait=0ms service=5ms status=404 bytes=728
2011-09-11T10:41:57+00:00 app[web.1]:
2011-09-11T10:41:57+00:00 app[web.1]:
2011-09-11T10:41:57+00:00 app[web.1]: Started GET "/y" for 93.186.31.80 at 2011-09-11 03:41:57 -0700
2011-09-11T10:41:57+00:00 app[web.1]:
2011-09-11T10:41:57+00:00 app[web.1]: ActionController::RoutingError (No route matches "/y"):
2011-09-11T10:41:57+00:00 app[web.1]:
2011-09-11T10:41:57+00:00 app[web.1]:
2011-09-11T10:41:57+00:00 app[web.1]:
2011-09-11T10:41:57+00:00 heroku[nginx]: 93.186.31.80 - - [11/Sep/2011:03:41:57 -0700] "GET /y HTTP/1.1" 404 728 "-" "Mozilla/5.0 (BlackBerry; U; BlackBerry 9300; en) AppleWebKit/534.8+ (KHTML, like Gecko) Version/6.0.0.546 Mobile Safari/534.8+" vivid-sky-685.heroku.com
2011-09-11T11:45:28+00:00 heroku[web.1]: Idl
2011-09-11T11:45:29+00:00 heroku[web.1]: State changed from up to down
2011-09-11T11:45:29+00:00 heroku[web.1]: State changed from down to created
2011-09-11T11:45:29+00:00 heroku[web.1]: State changed from created to starting
2011-09-11T11:45:30+00:00 heroku[web.1]: Stopping process with SIGTERM
2011-09-11T11:45:30+00:00 app[web.1]: >> Stopping ...
2011-09-11T11:45:30+00:00 heroku[web.1]: Process exited
2011-09-11T11:45:30+00:00 heroku[web.1]: Starting process with command `thin -p 16738 -e production -R /home/heroku_rack/heroku.ru start`
2011-09-11T11:45:33+00:00 app[web.1]: >> Thin web server (v1.2.6 codename Crazy Delicious)
2011-09-11T11:45:33+00:00 app[web.1]: >> Maximum connections set to 1024
2011-09-11T11:45:33+00:00 app[web.1]: >> Listening on 0.0.0.0:16738, CTRL+C to stop
2011-09-11T11:45:33+00:00 heroku[web.1]: State changed from starting to up
2011-09-11T12:53:00+00:00 heroku[web.1]: Idling
2011-09-11T12:53:01+00:00 heroku[web.1]: State changed from up to down
2011-09-11T12:53:02+00:00 heroku[web.1]: Stopping process with SIGTERM
2011-09-11T12:53:02+00:00 app[web.1]: >> Stopping ...
2011-09-11T12:53:02+00:00 heroku[web.1]: Process exited
2011-09-11T13:18:21+00:00 heroku[rake.1]: State changed from created to starting
2011-09-11T13:18:23+00:00 app[rake.1]: Awaiting client
2011-09-11T13:18:23+00:00 app[rake.1]: Starting process with command `bundle exec rake db:migrate`
2011-09-11T13:18:26+00:00 heroku[rake.1]: Process exited
2011-09-11T13:18:26+00:00 heroku[rake.1]: State changed from up to complete
2011-09-11T13:20:02+00:00 heroku[web.1]: Unidling
2011-09-11T13:20:02+00:00 heroku[web.1]: State changed from down to created
2011-09-11T13:20:02+00:00 heroku[web.1]: State changed from created to starting
2011-09-11T13:20:04+00:00 heroku[web.1]: Starting process with command `thin -p 48393 -e production -R /home/heroku_rack/heroku.ru start`
2011-09-11T13:20:06+00:00 app[web.1]: >> Thin web server (v1.2.6 codename Crazy Delicious)
2011-09-11T13:20:06+00:00 app[web.1]: >> Maximum connections set to 1024
2011-09-11T13:20:06+00:00 app[web.1]: >> Listening on 0.0.0.0:48393, CTRL+C to stop
2011-09-11T13:20:07+00:00 heroku[web.1]: State changed from starting to up
2011-09-11T13:20:07+00:00 app[web.1]:
2011-09-11T13:20:07+00:00 app[web.1]:
2011-09-11T13:20:07+00:00 app[web.1]: Started GET "/" for 118.137.144.220 at 2011-09-11 06:20:07 -0700
2011-09-11T13:20:08+00:00 app[web.1]:
2011-09-11T13:20:08+00:00 app[web.1]: ActionController::RoutingError (uninitialized constant PagesController):
2011-09-11T13:20:08+00:00 app[web.1]:
2011-09-11T13:20:08+00:00 app[web.1]:
2011-09-11T13:20:08+00:00 app[web.1]:
2011-09-11T13:20:08+00:00 heroku[router]: GET vivid-sky-685.heroku.com/ dyno=web.1 queue=0 wait=0ms service=403ms status=404 bytes=728
2011-09-11T13:20:08+00:00 heroku[nginx]: 118.137.144.220 - - [11/Sep/2011:06:20:08 -0700] "GET / HTTP/1.1" 404 728 "-" "Mozilla/5.0 (X11; Linux i686; rv:2.0) Gecko/20100101 Firefox/4.0" vivid-sky-685.heroku.com
采纳答案by Tony Nguyen
I got the same problem; however, after changing 1 line code of production.rb located in config/environments/production.rbfrom
我遇到了同样的问题;但是,在更改位于config/environments/production.rbfrom 中的 production.rb 的 1 行代码后
config.assets.compile = false
to
到
config.assets.compile = true
commit the new change. Then my sample app works fine on heroku
提交新的更改。然后我的示例应用程序在 heroku 上运行良好
回答by xji
I know it's an old problem but I ran into it too. I realized I didn't change the root route in config/routes.rbbefore pushing. Not changing it might result in a welcome page locally, but on heroku it will get the above error.
我知道这是一个老问题,但我也遇到了。我意识到config/routes.rb在推送之前我没有改变根路由。不更改它可能会导致本地出现欢迎页面,但在 heroku 上会出现上述错误。
回答by Ben Wheeler
I'm using postgresql, and I also had page not showing up on heroku.
我正在使用 postgresql,而且我的页面也没有显示在 heroku 上。
This command fixed it:
这个命令修复了它:
heroku run rake db:setup
and then
进而
heroku rake db:migrate
I had migrated before, but hadn't done the setup first.
我之前迁移过,但没有先完成设置。
I also had tried setting
我也试过设置
config.assets.compile = true
in production.rb, but that made no difference.
在 production.rb 中,但这没有区别。
回答by David
Have you tried running in production mode locally? Try rails server -e productionand see if you get the same error, which you can then debug. Also make sure you've done heroku rake db:migrate.
您是否尝试在本地以生产模式运行?尝试rails server -e production看看您是否遇到相同的错误,然后您可以对其进行调试。还要确保你已经完成了heroku rake db:migrate。
回答by Nick
In my case it was a missing starting page that did not cause a problem in development mode but did cause the above issue on heroku. The accepted answer on this threadsheds more light.
在我的情况下,它是一个丢失的起始页面,它没有在开发模式下导致问题,但在 heroku 上确实导致了上述问题。此线程上已接受的答案揭示了更多信息。
回答by limaBEAN
Ran into this problem as well. Solved it by setting a root route. In my case, root 'pages#home'in config/routes.rb
也遇到了这个问题。通过设置根路由解决了它。就我而言,root 'pages#home'在 config/routes.rb
If the root route is not set, you are redirected to localhost:3000. Hence,
如果未设置根路由,您将被重定向到 localhost:3000。因此,
The page you were looking for doesn't exist. You may have mistyped the address or the page may have moved.
您要找的页面不存在。您可能输入错误的地址或页面可能已移动。
回答by Saurav Prakash
1. Always set a root in routes. That's rails 101
1. 始终在路由中设置根。那是导轨 101
I wouldn't go for making asset pre-compilation false all the time. For production app I feel it enhances the overall speed if assets have been pre-compiled.
我不会一直让资产预编译为假。对于生产应用程序,我觉得如果资产已经预编译,它会提高整体速度。
2. As a rule of thumb I always run rake assets:precompilebefore pushing to git. Please try it. and then commit to git repository and then heroku. Do heroku restart
2. 根据经验,我总是rake assets:precompile在推送到 git 之前先运行。请尝试一下。然后提交到 git 存储库,然后提交到 heroku。做heroku restart
3. Another cause could be heroku rake db:migrate, please check if you did it
3. 另一个原因可能是heroku rake db:migrate,请检查你是否做了
4. Also this is my Gemfile setup for the development and production groups
4. 这也是我为开发和生产组设置的 Gemfile
group :development do
gem 'sqlite3'
end
group :production do
gem 'pg'
gem 'rails_12factor'
gem 'heroku-deflater'
end
回答by Isaac ts
I had the same problem, but the thing is that the app is missing the home like root. The default home page for Heroku is this HTMLthe default page. But if you try all your defined routes they will work like:
我遇到了同样的问题,但问题是该应用程序缺少像 root 一样的主页。Heroku 的默认主页是这个 HTML默认页面。但是,如果您尝试所有定义的路线,它们将如下工作:
appname.herokuapp.com/route
appname.herokuapp.com/route
回答by jerof
I got the same error but realized that I hadn't change the HTML verb from GET to ROOT in config/routes.rb file.
我遇到了同样的错误,但意识到我没有将 config/routes.rb 文件中的 HTML 动词从 GET 更改为 ROOT。
It was get "/hello", to: "application#hello"
它是 get "/hello", to: "application#hello"
I updated it to root "application#hello"
我将其更新为 root "application#hello"
I then pushed it to git and deployed it to production.
然后我将它推送到 git 并将其部署到生产中。
回答by Aarvy
I was facing the same error because I pushed same non-master branch to heroku master using this command git push heroku master. Which obviously cause conflicts.
我面临同样的错误,因为我使用此命令将相同的非主分支推送到 heroku master git push heroku master。这显然会引起冲突。
I also checked the routes using heroku run rake routes. But the output was not my actual routes. Not even single one.
The proper way to push your non-master branch to heroku master is
我还使用heroku run rake routes. 但输出不是我的实际路线。连一个都没有。
将非 master 分支推送到 heroku master 的正确方法是
git push -f heroku your_branch_name:master
git push -f heroku your_branch_name:master

