I'm new to Ruby and Ruby on Rails, am using Ruby 1.9.2 and Rails 3.2.5 on Max OSX Lion, and am working my way through the book "Agile Web Development with Rails (4th Edition)".
I've created their sample depot app using the following commands outlined in Chapter 6:
- rails new depot
- rails generate scaffold Product title:string description:text image_url:string price:decimal
- rake db:migrate
- rails server
When I point Safari to "http://localhost:3000/products" I get the following Action Controller: Exception Caught error message instead of seeing a product list page:
Routing Error
No route matches [GET] "/products"
Try running rake routes for more information on available routes.
Running "rake routes" in Terminal gives me:
products GET /products(.:format) products#index
POST /products(.:format) products#create
new_product GET /products/new(.:format) products#new
edit_product GET /products/:id/edit(.:format) products#edit
product GET /products/:id(.:format) products#show
PUT /products/:id(.:format) products#update
DELETE /products/:id(.:format) products#destroy
The following line was automatically added to routes.rb.
resources: product
There is also an index method in products_controller.rb.
class ProductsController < ApplicationController
# GET /products
# GET /products.json
def index
@products = Product.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @products }
end
end
A search of the book's errata and forums did not turn up any possible solutions.
Thanks in advance.