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:
- script/generate controller Products
- script/generate model Products
- rake db:migrate
- modified products_controller.rb to add: def index() { @products = Product.all}
- (error: uninitialized constant ProductsController::Product)
- ideally, dump all orders in the view
What's the fix?
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.
精彩评论