Ruby on Rails는 MVC(Model-View-Controller) 패턴과 "설정보다 관례(Convention over Configuration)" 철학을 따르는 풀스택 웹 애플리케이션 프레임워크입니다.
이 가이드의 세부 치트시트 목록
- Rails ActiveRecord 모델 치트시트
- Rails 컨트롤러 치트시트
- Rails 라우팅 치트시트
- Rails 데이터베이스 마이그레이션 치트시트
- Rails 폼 헬퍼 치트시트
- Rails 뷰 헬퍼 치트시트
- Rails 국제화(i18n) 치트시트
- Rails 팁 & 트릭 치트시트
자주 사용하는 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>