十手で作る簡単ウェブ アプリケーション with Ruby on Rails

例えば、「CD情報を扱うウェブ アプリケーション」を作る事にする

  1. 任意のディレクトリに移動
  2. rails mylib →mylibディレクトリと、必要なファイルが自動的に生成される
  3. mylibディレクトリに移動
  4. そこを基点として、下記の内容を/app/models/disk.rbとして作成
    • class Disk < ActiveRecord::Base
      end
  5. 同じく/app/controllers/mylib_controller.rbを作成
    • class MylibController < ApplicationController
        scaffold :disk
      end
  6. MySQLへログイン
  7. create database mylib_development; →データベースが用意される
  8. create table mylib_development.disks (
      id int not null auto_increment,
      title char(255) not null,
      artist char(255) not null,
      year int(4) not null,
      label char(255) not null,
      primary key (id)
    );
    →テーブルが作られる
  9. MySQLからログアウト
  10. /config/database.ymlを開き、developmentのpasswordを入力する

あとはruby script/serverRails付属の簡易ウェブ サーバが起動、http://localhost:3000/mylibにアクセスすれば出来上がり。
ヽ(・∀・)ノやたー