반응형
✅ 1. 모델 생성rails generate model Post title:string content:textrails db:migrate# app/models/post.rb - 모델 유효성 추가class Post ✅ 2. 컨트롤러 생성 rails generate controller Posts// app/controllers/posts_cotroller.rbclass PostsController ✅ 3.라우트 설정// config/routes.rbRails.application.routes.draw do resources :posts, only: [ :index, :new, :create, :show, :edit, :update, :destroy ] root "posts#new"end✅ 4. vie..
1. 라우팅 (Routing)라우팅은 URL 요청을 특정 컨트롤러의 액션에 매핑하는 역할로, Rails에서 config/routes.rb 파일에 라우팅을 직접 설정할 수 있습니다. 먼저 기본적인 라우팅 설정은 다음과 같습니다.Rails.application.routes.draw do resources :articles get "articles", to: "articles#index" # 모든 기사 목록 get "articles/new", to: "articles#new" # 새 기사 작성 폼 post "articles", to: "articles#create" # 새 기사 생성 get "articles/:id", to: "articles#show" # 특정 기사 보기 get "articl..
1. Ruby on Rails 란?Ruby on Rails(RoR)는 Ruby 프로그래밍 언어를 기반으로 작성된 오픈 소스 웹 애플리케이션 프레임워크로, MVC(모델-뷰-컨트롤러) 패턴을 기반으로 한, 웹 애플리케이션 언어입니다. Ruby on Rails의 특징으로는 다음과 같습니다.빠른 개발: 기본적으로 Rails는 코드의 양을 줄이고, 생산성을 높이기 위한 다양한 도구와 기능을 제공해 빠른 프로토타이핑을 지원Convention over Configuration: 기본적인 설정이 자동으로 이루어져 개발자가 설정에 신경 쓰지 않고 비즈니스 로직에 집중함DRY(Don't Repeat Yourself): 코드 중복을 피하고 재사용성을 높이는 것을 지향하여 유지보수성을 향상 강력한 커뮤니티: 활발한 커뮤니티와..
1. 메타프로그래밍루비는 메타프로그래밍을 지원하여 프로그램이 실행 중 코드 구조를 변경할 수 있고, 이를 통해 동적 메서드 생성, 속성 정의 등을 할 수 있습니다. 예를 들어 method_missing을 사용해 호출되지 않은 메서드에 대한 처리를 정의합니다.class DynamicMethod def method_missing(method_name, *args) "You called #{method_name} with #(args.inspect)" end enddm = DynamicMethod.new puts dm.undefined_method2.블록과 프로시저루비에서 블록은 메서드에 전달할 수 있는 코드 조각으로, 블록을 사용해 코드의 재사용성을 높이고, 더 유연한 메서드를 만들 수 있습..