1
votes

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:

  1. rails new depot
  2. rails generate scaffold Product title:string description:text image_url:string price:decimal
  3. rake db:migrate
  4. 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.

1

1 Answers

0
votes

Figured it out - I had another instance of the WEBrick server running in another terminal window but it was for a demo application from a previous chapter.

Lesson learned. Make sure you run the local server from the directory of the Rails application you want to test.