Routing Error No route matches "/employee/list" with {:method=>:get}


I am very frustrated by this error when I just put together a very simple project from one of the textbook on RoR:   Routing Error      No route matches "/employee/list" with {:method=>:get}

For your reference,

#The following is EmployeesController.rb

class EmployeesController < ApplicationController    scaffold :employee # create scaffold code for controller

   # override scaffold list method    def list       @employees = Employee.find( :all ) # return an array of all Employees    end # method list end # class EmployeeController

# The following is Employee.rb class Employee < ActiveRecord::Base end

# And the following is list.rhtml,

<?xml version = "1.0" encoding = "utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"    ";&gt;

<!-- Fig. 20.22 app/views/employees/list.rhtml --> <!-- A view that displays a list of Employees. --> <html xmlns = ";&gt; <head>    <title>List of Employees</title> </head> <body style="background-color: lightyellow">    <h1>List of Employees</h1>    <ol>    <% for employee in @employees %>    <!-- create a list item for every employee with his full name -->       <li><%= employee.first_name %> <%= employee.last_name %></li>    <% end %>    </ol> </body> </html>

PLEASE HELP!!! Zhiguang

if your controller is employees then (in the absence of any extra routes being defined) the url you should be hitting is /employees/list


Yes that fixes it, but only if I comment out the line

     scaffold :employee # create scaffold code for controller

in EmployeesController.rb. If I keep that line there, I still have trouble when hitting /employees/new etc.

I think I need help with the way how "scaffold" works. Thanks!

That macro was removed from recent versions of Rails. It sounds like your book is rather out of date unfortunately.

You can still generate scaffolding like so (from the command line):

    script/generate scaffold employees

That will give you the controller, model, and test files rather than generating most of the code at runtime like the scaffold method did before.