1, set up the project: rails bookstore-d mysql

Add "-d mysql" database are changed to mysql; then want to modify \ bookstore \ config / following database.yml,

Such as my changes are as follows


development:

adapter: mysql

encoding: utf8

database: bookstore_development

username: root

password: root

host: localhost

test:

adapter: mysql

encoding: utf8

database: bookstore_test

username: root

password: root

host: localhost

production:

adapter: mysql

encoding: utf8

database: bookstore_production

username: root

password: root

host: localhost



If you think someone above to see a bad mood, a little skill can modify the following, programmers look likes the style.


defaults: & defaults

adapter: mysql

encoding: utf8

username: root

password: root

socket: / opt/local/var/run/mysql5/mysqld.sock

development:

database: blog_development

<<: * Defaults

test:

database: blog_test

<<: * Defaults

production:

database: blog_production

<<: * Defaults



Some people here crawl database. Because there is no format in accordance with the rails Writing YML file. Database.yml so ah on space inside is best not to arbitrarily increase or removed.

2, set up databases, the implementation of
1.cd bookstore
2. Rakedb: create: all
Appear
c: \ Ruby \ projects \ bookstore> rake db: create: all
(inc: \ Ruby \ projects \ bookstore)
"db/development.sqlite3 already exists"
"db/production.sqlite3 already exists"
"db/test.sqlite3 already exists"


Should be the default SQLite are set up at the original works when the database was set up, if it is to use MySQL, then less will not be able to

3, set up model

4, ruby script / generate scaffold book title: string author: string publishdate: datetime
4. Finally, migration file generated database table
rake db: migrate

rake db: migrate

5. To start the server

ruby script / server

ps should be replaced by Mongrel for us, so start the application server is Mongrel if you want to use WEBrick, use 'script / server webrick'

The above summary of the work:

o install Rails
gem install rails - include-dependencies

o use rails command to create a program
rails bookstore

o Create a database using rake commands
rake db: create: all

o use script / generate command to generate the scaffolding
ruby script / generate scaffold book title: string author: string publishdate: datetime

o files generated by migration database table
rake db: migrate

o use script / server command to start server
ruby script / server

o your browser input data Edit
http://localhost:3000/books