If the ROR development environment is not installed on the machine, see Ruby on Rails + MySQL development environment to build the environment.
Note: ror's classic book "agile web development-agile web development using rails" currently only supports the second edition of Chinese, the environment in which the author writes the book is rails 1.x. now the rails version has been updated to 2.3.5, and many things have changed. If you refer to the second version of the book to do it step by step, you cannot do it at all. (Currently the book has released the third version, but there is no translation version in China, http://hlee.javaeye.com/blog/363605 here can download the English electronic version of the book)
The following commands are completed in Windows Command Line Mode:
1. Enter the working directory (in this example, D: \ mydoc \ ror \)
D:
CD mydoc \ ror
2. Create a rails project with MySQL: depot)
D: \ mydoc \ ror \ depot> rails-D MySQL depot
3. edit database. yml, modify username and password, and create the database corresponding to database. yml in MySQL. (Note that the encoding mode is utf8)
Note: Do not install the latest version 5.1 in MySQL. We recommend that you use version 5.0. Otherwise, rake may encounter problems during database migration.
4. Test whether it can run.
D: \ mydoc \ ror \ depot> Ruby script/Server
If you are lucky, you can browse the local http: // localhost: 3000/to see the following picture.
5. Add the product entity model
D: \ mydoc \ ror \ depot> Ruby script/generate scaffold product title: String Description: Text image_url: String
Here we will create a product entity class with three members title, description, image_url
6. Synchronize entities to the database
D: \ mydoc \ ror \ depot> rake DB: migrate
After execution, a table products is automatically generated in the MySQL database depot_development.
Note: In. net, the LINQ to SQL/entity statements first create tables in the database and then automatically map them to entity classes, which is the opposite in ror.
Okay. It's basically done!
Browse: http: // localhost: 3000/products.
(Note: ror is a pure MVC Framework. If you are familiar with Asp.net MVC, you can easily access ror)
Product list page:
Modify the product page: