빠른 참조

Ruby on Rails 개요 치트시트

Ruby on Rails 고급 아키텍처 치트시트: MVC 규칙, CLI 명령어, 컨트롤러, 뷰, 레이아웃 및 헬퍼.

· 게시일

Ruby on Rails는 MVC(Model-View-Controller) 패턴과 "설정보다 관례(Convention over Configuration)" 철학을 따르는 풀스택 웹 애플리케이션 프레임워크입니다.

이 가이드의 세부 치트시트 목록


자주 사용하는 CLI 명령어

# PostgreSQL 기반의 새 Rails 프로젝트 생성
rails new myapp --database=postgresql

# localhost:3000에서 개발 서버 시작
bin/rails server

# 대화형 Rails 콘솔 실행
bin/rails console

# 데이터베이스 마이그레이션 실행
bin/rails db:migrate

컨트롤러 및 액션 관례

class ProjectsController < ApplicationController
  before_action :set_project, only: [:show, :edit, :update, :destroy]

  def index
    @projects = Project.all
  end

  def show
  end

  private

  def set_project
    @project = Project.find(params[:id])
  end
end

레이아웃 및 Yielding

app/views/layouts/application.html.erb 파일 구조:

<!doctype html>
<html>
  <head>
    <title><%= content_for?(:title) ? yield(:title) : "Default App" %></title>
    <%= csrf_meta_tags %>
    <%= csp_meta_tag %>
    <%= stylesheet_link_tag "application" %>
    <%= javascript_importmap_tags %>
  </head>
  <body>
    <%= yield %>
  </body>
</html>

참고자료

관련 주제