Example of Rails scaffolding

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.