Scaffolding is a very easy method for rails. Some simple addition, deletion, modification, and query scaffolding can be implemented, saving unnecessary trouble. How can we use rails scaffolding? Let's explain it today.
. Specify the port to start the rails Project
Copy codeThe Code is as follows: ruby script/server webrick-p 3000
0. Create a project
Copy codeThe Code is as follows: rials demoshop
1. create products with scaffolding (control model display data)
Copy codeThe Code is as follows: script/generate scaffold product title: string description: text image_url: string
2. If an error occurs during creation(Destroy scaffold pronduct product object)
Copy codeThe Code is as follows: script/destroy scaffold pronduct
3. Create an sqlite table(You must have created the previous step)
Copy codeThe Code is as follows: rake db: migrate
4. Run the sqlite command to view the current migrate version of the current project.
Copy codeThe Code is as follows: sqlite3 db/development. sqlite3 "select version from schema_migrations"
5. view route information
Copy codeThe Code is as follows: rake routes
6. Add a field scaffold for database migration
Copy codeThe Code is as follows: script/generate migration add_price_to_product price: decimal
Then perform step 3.
7. debugging
Copy codeThe Code is as follows: script/console
8. Create only one action for one controller
Copy codeThe Code is as follows: ruby script/generate controller store index