简体   繁体   中英

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.

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.

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:

class IndexController < ApplicationController
  def index
  end
end

and in my app > views > index folder I have a file named 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.

Since I'm using Heroku my gem file contains this:

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. 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

root to: 'index#index'

This will make http://safe-peak-2383.herokuapp.com show the index of your index controller.

Remember to push all these changes to github then heroku for them to take effect

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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