Rails Scaffolding Use Example _ruby topic

Source: Internet
Author: User
Tags sqlite

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:
Rials Demoshop

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:
Rake Db:migrate

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:
Rake routes

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:
Script/console

8. Create only one action for a controller
Copy Code code as follows:
Ruby Script/generate Controller Store Index

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.