Tuesday, May 19, 2015

Ruby on Rails Note - 05/19/2015

1. To create a new project.
    $ rails new [project name]

2. Create a scaffold. A scaffold is a full set of model, database migration for that model, controller to manipulate it, view to view and manipulate the data, and a test suite for each of the above.
    $ rails generate scaffold Product \
            title:string description:text image_url:string price:decimal

The default database for Rails development is SQLite3. The config/database.yml file tells Rails where to look for the database.

3. To migrate database.
    $ rake db:migrate

The migration file is xxxxxxxxxxxxxx_create_xxxx.rb. A migration represents a change we want to make to the data, expressed in a source file in database-independent terms. These changes can update both the database schema and the data in the database tables.

4. To start rails server.
    $rails server

5. To import seed data to the database.
    $rails db:seed

The data can be defined in db/seed.rb.

No comments:

Post a Comment