Generate the Model DIRECTIONS:Follow along as you begin learning the basics of Ruby on Rails, a powerful framework for creating dynamic, data-driven websites. ❏
Login to Cloud9
● Go to https://c9.io/web/login
❏
Open Workspace
● Click OPEN on your ruby-on-rails workspace tile
❏
Make Sure Your Application is Running
● Change directory to dozerslist , your application’s directory: $ cd dozerslist
● Launch the Rails server: $ rails s -b $IP -p $PORT ❏
Create Item Model
● Use the rails generator to create a table and migration: $ rails g model item
As you can see, the command created a migration and a model ❏
Look Closer At the Migration
● In the text editor, look at the migration file ( YYYYMMDDHHMMSS_create_items.rb) : class CreateItems . dump items
The output should resemble the following: PRAGMA foreign_keys=OFF; BEGIN TRANSACTION; CREATE TABLE "items" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL, "description" varchar NOT NULL, "category" varchar NOT NULL, "flagged" boolean, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL); COMMIT;
❏
Look Closer At the Schema File
● In the text editor, verify that your file looks like the one below:
# encoding: UTF-8 # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. # # Note that this schema.rb definition is the authoritative source for your # database schema. If you need to create the application database on another # system, you should be using db:schema:load, not running all the migrations # from scratch. The latter is a flawed and unsustainable approach (the more migrations # you'll amass, the slower it'll run and the greater likelihood for issues). # # It's strongly recommended that you check this file into your version control system. ActiveRecord :: Schema . define ( version : 20150724014026 ) do create_table "items" ,force : : cascade do | t | t . string "name" , null : false t . string "description" ,null : false t . string "category" , null : false t . boolean "flagged" t . datetime "created_at" , null : false t . datetime "updated_at" , null : false end end