시간/날짜 관련 표현식

IT(Old)/RubyOnRails-Tip 2008. 1. 21. 12:14

t = Time.now

t.strftime("%Y/%m/%d %H:%M:%S")
=>2008/01/21 12:13:30


t.strftime("%y/%m/%d %I:%M:%S %p");
=>08/01/21 12:13:30 PM

초를 더할때

t2 = t + 30

5일을 더할때
t3 = t + 60*60*24*5

크기로 비교 가능

t2 < t3


today = Data.today
christmas = Date.new(2007,12,25)

날짜는 +연산을 하면 일자가 더해진다.

테이블 명명규칙

IT(Old)/RubyOnRails-Tip 2008. 1. 21. 09:47

rails에서는

테이블명에는 복수형을(끝에 s붙임)

모델은 단수형을 사용한다.

그래야...자동으로 테이블 일대일매핑이 가능하다.

ㅡ.ㅡ

my sql DB config(database.yml)

IT(Old)/RubyOnRails-Tip 2008. 1. 21. 09:30

# SQLite version 3.x
#   gem install sqlite3-ruby (not necessary on OS X Leopard)
development:
  adapter: mysql
  database: test
  username: root
  password: xxxxx
  encoding: utf8

# Warning: The database defined as 'test' will be erased and
# re-generated from your development database when you run 'rake'.
# Do not set this db to the same as development or production.
test:
  adapter: mysql
  database: test
  username: root
  password: xxxxx
  encoding: utf8

production:
  adapter: mysql
  database: test
  username: root
  password: xxxxx
  encoding: utf8

ruby 서버 포트 변경

IT(Old)/RubyOnRails-Tip 2008. 1. 21. 09:16
ruby scriptserver -p 80