Header

  1. View current page

    studioego

Profile_img_60x60_01
0

레일스 명령어·메소드 요약집

레일스 프로젝트 디렉토리 생성

rails app_name

파일 생성(generator) 스크립트

대상 명령어
모델  ruby script/generate model ModelName
컨트롤러  ruby script/generate controller ControllerName
스캐폴드  ruby script/generate scaffold ModelName ControllerName
마이그레이션  ruby script/generate model migration MigrationName
도움말  ruby script/generate --help
generator 도움말  ruby script/generate gererator_name --help

파일 삭제(destroyer) 스크립트

대상 명령어
모델  ruby script/destroy model ModelName
컨트롤러  ruby script/destroy controller ControllerName
스태폴드  ruby script/destroy migration MigrationName
마이그레이션  ruby script/destroy scaffold ModelName controllerName
도움말  ruby script/destroy --help
destroyer 도움말  ruby script/destroy destroyer_name --help

서버구동

ruby script/server -p 포트번호 -e 구동_환경_이름

콘솔스크립트

script/console 구동_환경_이름

플러그인 스크립트

명령어 설명
script/plugin discover  플러그인 목록 업데이트(레일스 위키에 리스트된 플러그인의 경우, 이름으로 설치가 가능해짐
script/plugin list  이름으로 설치 가능한 플러그인 목록 보기
script/plugin install plugin_name  플러그인의 설치(이름을 사용)
script/plugin install URL  플러그인의 설치(URL 이용)
script/plugin update  설치되어 있는 플러그인을 모두 업데이트

액티브 레코드 모델의 find 메소드

User.find(3)

User.find_by_login("gildong")

User.find :first

              :conditions => ["name = ?", "홍길동"]

User.find :all

              :conditions => ["age > ? AND gender = ?", 18, "male"],

              :order  => "created_at DESC",

              :offset => 100,

              :limit => 10,

              :readonly => true

@article_pages, @articles = paginate :articles,

          :select => "articles.*",

          :conditions => ["taggings.tag_id=?", params[:id]],

          :joins => "inner join taggings on articles.id = taggings.article_id",

          :per_page => 10

 

액티브 레코드 관계(Association) 설정

belongs_to :user

has_one :birth_record,

             :dependent => :destroy

has_many :friends,

                :dependent => :destroy

has_many :tags,

                :through => :taggings

 

액티브 레코드 검증(Validation) 메소드

validates_presence_of :name,

                                 :message => "반드시 존재해야 하는 필드입니다."

validates_uniqueness_of :login,

                                    :message => "이미 사용되고 있는 로그인 ID입니다."

validates_numericality_of :login,

                                     :in => 4..10

                                     :too_short => "너무 짧습니다."

                                     :too_long => "너무 깁니다."

History

Last edited on 07/30/2008 18:12 by StudioEgo

Comments (0)

You must log in to leave a comment. Please sign in.