728x90
반응형
이 튜토리얼에서는 migration 을 사용하지 않고, Model 에서 직접 스키마를 작성하고 Table 을 생성하도록 하였다. 그리고, Ramaze (2012.12.08) 에서 테스트를 진행하였다.
관련 모듈 설치
프로젝트 생성
기본 웹서버 변경 -> task/ramaze.rake 에서 :webrick 을 :thin 으로 수정 웹서버 시작 테스트
app.rb 에 다음 추가
model/init.rb 에 다음 추가
model/admin.rb 생성
controller/init.rb 에 다음을 추가
controller/admin.rb 생성
프로젝트를 실행하고 브라우저에서 http://localhost:3000/admin 을 접근해본다. 이제, controller/admin.rb 의 index 를 다음과 같이 변경한다.
view 디렉토리 생성
view/admin/index.xhtml 생성
프로젝트를 실행하고 브라우저에서 http://localhost:3000/admin 을 접근해서 데이터 목록이 뜨면 정상이다.
$ apt-get install libsqlite3-dev sqlite3
$ gem install ramaze sequel thin sqlite3
$ mkdir -p /opt/project/ramaze
$ cd /opt/project/ramaze
$ ramaze create web
$ cd /opt/project/ramaze/web
$ thin start
db/model 폴더 생성
$ cd /opt/project/ramaze/web
$ mkdir -p db
$ mkdir -p model
require 'sequel'
# Open the accounts database
DB = Sequel.connect('sqlite://db/web.db')
# Initialize controllers and models
require __DIR__('model/init')
require __DIR__('controller/init')
require __DIR__('admin')
# coding : utf-8
require 'sequel'
class Admin < Sequel::Model(:admins)
plugin :schema
set_schema do
primary_key :id
String :login, :unique => true, :empty => false
String :password, :empty => false
String :name
String :email
String :mobile_phone
String :level, :default => '00'
end
# Create the database table if it doesn't exists
# Also add a admin
if ! table_exists?
create_table
create :login => 'hong', :password => 'hong1234', :name => '홍길동', :email => 'hong@test.com', :mobile_phone => '010-5555-5555', :level => '00'
create :login => 'jang', :password => 'jang1234', :name => '장영실', :email => 'jang@test.com', :mobile_phone => '010-6666-6666', :level => '01'
end
end
require __DIR__('admin')
class AdminController < Controller
map '/admin'
def index
'Admin Test'
end
end
def index
@admins = Admin.all
end
$ cd /opt/project/itsm_ramaze/web/view
$ mkdir admin
<h1> Admin Test Page </h1>
<?r @admins.each do |admin| ?>
#{admin.login}
#{admin.name}
#{admin.email}
#{admin.mobile_phone}
#{admin.level}
<br/>
<?r end ?>
728x90
반응형
'Programming > Ruby' 카테고리의 다른 글
(Ruby) Ramaze 에서 JSON 으로 응답하기 (0) | 2012.11.21 |
---|---|
(Ruby) Ramaze Simple Tutorial (with Sequel) (0) | 2012.11.19 |
(Ruby) 여러 디렉토리의 사이즈를 구하고 크기 순으로 정렬하기 (0) | 2012.06.14 |
(Ruby) 특정 디렉토리 밑에 있는 파일중에 200MB 넘는 파일 찾기 (0) | 2012.05.25 |
(Ruby) JRuby 1.6.6 인코딩 관련 버그 (0) | 2012.02.13 |