본문 바로가기

.Tip

Ruby on Rails

  1. Models / Views / Controllers 관계
    1. Model- View- Controller Architecture

      image

      - Model
           모델은 Database와 연동하여, data 관리함

      - View
          뷰는 Model내의 Data을 이용하여, UI부분을 담당한다.

      - Controller
          컨트롤러는 Model과 연동하여, 외부에서 Event들을 받아서 처리하고,
          이를 사용자에게 적절한 View을 제공한다.
    2. Rails & MVC

      image 

  2. Instant Gratification
    1. Creating New Application
      > rails app
      (다음 폴더/ 파일들이 생성됨)

      image

      > ruby script/server
      : 서버 동작
      : http://localhost:3000
    2. Hello Rails!! (ActionController)
      > ruby script/generate controller Say //Say Controller 생성 Script

      - In app/controllers/say_controller.rb

      image

      - 다음 처럼 Definition을 추가해본다.

      image

      - Template 추가
        In app/views/say/hello.rhtml

      image

      - http://localhost:3000/say/hello 실행해보자

      - 다음은 Controller / Views의 위치.

      image