
ActiveRecord로 데이터 다루기 — CRUD의 정석
·
Ruby On Rails
Rails에서 데이터베이스와 소통하는 방식은 ActiveRecord를 통해 이루어집니다. ActiveRecord는 ORM(Object-Relational Mapping) 역할을 하며, 데이터베이스의 테이블과 Ruby 객체를 연결시켜줍니다. 이 글에서는 Rails의 핵심 기능인 CRUD (Create, Read, Update, Delete)를 ActiveRecord를 통해 어떻게 다루는지 정리해보겠습니다.📘 모델 생성$ bin/rails generate model Post title:string content:text$ bin/rails db:migrate위 명령어로 posts 테이블이 생성되고, Post 모델이 생성됩니다. 이제 이 Post 모델로 DB 조작이 가능해집니다.🆕 Create (데이터 생..