views:

22

answers:

1

I'm trying to understand Rails from the ground up. I want to learn how to manually create basic show-all/show-single/CRUD functionality in the framework.

I currently am working on the display-all functionality, but am stopped by an error when I try to request all items in the Products db

Here are the steps I've taken so far:

  1. script/generate controller Products
  2. script/generate model Products
  3. rake db:migrate
  4. modified products_controller.rb to add: def index() { @products = Product.all}
  5. (error: uninitialized constant ProductsController::Product)
  6. ideally, dump all orders in the view

What's the fix?

+3  A: 

When you generate your model you should be using either the lower case plural version or the Camel case singular.

so script/generate model Product or script/generate model product

In summary a model Product lives in app/models/product.rb and uses a database table products. When you have multi-word model names such as OrderItem this lives in app/models/order_item and uses a database table called order_items

Your original question also does not show any columns added when the model generator was run, I assume you have left those out for conciseness. Otherwise you may have a table with very few columns.

Steve Weet
Right. Your model should be singular, your controller for that model should be plural.
rspeicher
yes, left out columns for brevity
montooner