I’m getting started with Ruby on Rails and am following an online tutorial. The tutorial had me modify my routes.rb file by adding the following line:
resources :people
I also typed in rails generate controller People previously. controllers/people_controllers.rb looks like this:
class PeopleController < ApplicationController
end
Everything looks good to me. However, http://0.0.0.0:3000/people gives me an error:
Unknown action
The action 'index' could not be found for PeopleController
I don’t think I should need to do this, but when I add:
def index
end
to my controller, and refresh the page, I get the following error instead:
Template is missing
Missing template people/index, application/index with {:handlers=>[:erb, :builder], :locale=>[:en, :en], :formats=>[:html]}. Searched in: * "/Users/myuser/projects/project_manager/app/views"
I’m using the newest version of Ruby, and Rails v3. Everything was installed today. What could be wrong here?
You’ve created the controller but not defined the view for it. Add a file called
index.html.erbin directoryapp/views/people.Alternatively you can re-run the controller generator to generate the index view:
Also it is a good idea to read the Rails Guides. For your understanding of views and rendering read this.