[英]Ruby on Rails / Heroku - The page you were looking for doesn't exist
I realise this is a very common question but I am currently teaching myself ruby on rails and after going through the gargantuan task of getting an app set up on Heroku I've encountered my first problem. 我意识到这是一个非常普遍的问题,但是我目前正在自学红宝石,在完成了在Heroku上设置应用程序的艰巨任务之后,我遇到了第一个问题。
I thought something was broken since when I click the About your application's environment
link I get the page not found error
but read that's ok as that should only work in the dev environment. 我以为发生了一些问题,因为当我单击“ About your application's environment
链接时, page not found error
但没关系,因为那只能在开发环境中工作。
So, I went ahead and created a controller and a view with the following command: 因此,我继续使用以下命令创建了一个控制器和一个视图:
rails generate controller Index
In my app > controllers
folder I have a file called index_controller.rb
which contains the following: 在我的app > controllers
文件夹中,我有一个名为index_controller.rb
的文件,其中包含以下内容:
class IndexController < ApplicationController
def index
end
end
and in my app > views > index
folder I have a file named index.html.erb
在我的app > views > index
文件夹中,我有一个名为index.html.erb
的文件
<html>
<head>
<title>Test Site</title>
</head>
<body>
<h1>Test</h1>
</body>
</html>
But when I visit http://safe-peak-2383.herokuapp.com/index/index/ I get the page not found error. 但是,当我访问http://safe-peak-2383.herokuapp.com/index/index/时,出现页面未找到错误。
Since I'm using Heroku my gem file contains this: 由于我使用的是Heroku,因此我的gem文件包含以下内容:
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
Any ideas? 有任何想法吗?
If you visit http://safe-peak-2383.herokuapp.com you will see the getting started page. 如果您访问http://safe-peak-2383.herokuapp.com ,则会看到入门页面。 I seems like you have not set the root route for your app. 似乎您尚未设置应用程序的根路由。
first, 第一,
git rm public/index.html
This will get rid of the getting started page when you visit the root path of your app 当您访问应用程序的根路径时,这将摆脱入门页面
next, in config/routes.rb
接下来,在config/routes.rb
root to: 'index#index'
This will make http://safe-peak-2383.herokuapp.com show the index of your index controller. 这将使http://safe-peak-2383.herokuapp.com显示索引控制器的索引。
Remember to push all these changes to github then heroku for them to take effect 记住将所有这些更改推送到github,然后将其推送到heroku,以使它们生效
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.