Scaffolding is a very easy way to rails, some simple additions and deletions to check the scaffolding can be achieved, save us unnecessary trouble, so how to use rails scaffolding, today to explain.
. Specify port Start Rails project
Copy Code code as follows:
Ruby Script/server Webrick-p 3000
0. Create a project
Copy Code code as follows:
1. Create products with scaffolding (Control model display data)
Copy Code code as follows:
Script/generate Scaffold Product title:string description:text image_url:string
2. If the creation is wrong destroy these(Destroy destroys scaffold scaffold pronduct Product object)
Copy Code code as follows:
Script/destroy Scaffold Pronduct
3. To create a SQLite table(Must have the previous step to create)
Copy Code code as follows:
4. Use the SQLite command to view current project migrate current version
Copy Code code as follows:
Sqlite3 db/development.sqlite3 "Select version from Schema_migrations"
5. View the routing situation
Copy Code code as follows:
6. Database Migration Add one field scaffold
Copy Code code as follows:
Script/generate Migration Add_price_to_product Price:decimal
And then perform the 3 steps
7. Debugging
Copy Code code as follows:
8. Create only one action for a controller
Copy Code code as follows:
Ruby Script/generate Controller Store Index