2

我意识到这是一个非常常见的问题,但我目前正在自学 ruby​​ on rails,在完成了在 Heroku 上设置应用程序的艰巨任务后,我遇到了第一个问题。

我认为有些东西坏了,因为当我单击About your application's environment链接时,我得到了page not found error但是读没关系,因为它应该只在开发环境中工作。

因此,我继续使用以下命令创建了一个控制器和一个视图:

rails generate controller Index

在我app > controllers的文件夹中,我有一个名为的文件index_controller.rb,其中包含以下内容:

class IndexController < ApplicationController
  def index
  end
end

在我app > views > index的文件夹中,我有一个名为index.html.erb

<html>
    <head>
        <title>Test Site</title>
    </head>
    <body>
        <h1>Test</h1>
    </body>
</html>

但是当我访问http://safe-peak-2383.herokuapp.com/index/index/时,我得到了找不到页面的错误。

由于我使用的是 Heroku,因此我的 gem 文件包含以下内容:

group :development, :test do
  gem 'sqlite3'
end
group :production do
  gem 'pg'
end

有任何想法吗?

4

1 回答 1

1

如果您访问http://safe-peak-2383.herokuapp.com,您将看到入门页面。我好像你还没有为你的应用设置根路由。

第一的,

git rm public/index.html

当您访问应用程序的根路径时,这将摆脱入门页面

接下来,在config/routes.rb

root to: 'index#index'

这将使http://safe-peak-2383.herokuapp.com显示您的索引控制器的索引。

请记住将所有这些更改推送到 github 然后 heroku 让它们生效

于 2013-05-22T20:28:36.533 回答