开发者

Trying to manually recreate a simple generate/scaffolding script

开发者 https://www.devze.com 2023-01-03 09:38 出处:网络
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'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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消