十手で作る簡単ウェブ アプリケーション with Ruby on Rails
例えば、「CD情報を扱うウェブ アプリケーション」を作る事にする
- 任意のディレクトリに移動
rails mylib
→mylibディレクトリと、必要なファイルが自動的に生成される- mylibディレクトリに移動
- そこを基点として、下記の内容を/app/models/disk.rbとして作成
class Disk < ActiveRecord::Base
end
- 同じく/app/controllers/mylib_controller.rbを作成
class MylibController < ApplicationController
scaffold :disk
end
- MySQLへログイン
create database mylib_development;
→データベースが用意される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)
);- MySQLからログアウト
- /config/database.ymlを開き、developmentのpasswordを入力する
あとはruby script/server
でRails付属の簡易ウェブ サーバが起動、http://localhost:3000/mylibにアクセスすれば出来上がり。
ヽ(・∀・)ノやたー