站内导读
定位:Ruby on Rails 是用 Ruby 编写的全栈 Web 应用框架,按模型-视图-控制器(MVC)模式组织应用,构建数据库驱动的网站所需的组件一应俱全。 核心能力:模型层由 Active Record 负责把数据库表映射为对象并承载业务逻辑,视图层用模板生成页面,控制器处理请求与响应,三层分工明确;「约定优于配置」的设计让团队能快速把产品做出来并持续迭代。 适用人群:想用 Ruby 快速开发数据库型 Web 应用的团队和独立开发者。GitHub 上已有 5.9 万余 star。
位置づけ:Ruby on Rails は Ruby 製のフルスタック Web アプリケーションフレームワークで、モデル・ビュー・コントローラ(MVC)パターンに沿ってアプリを構成し、データベース駆動の Web アプリに必要な部品が一通りそろっています。 主な機能:モデル層は Active Record がデータベースの表をオブジェクトに対応づけ業務ロジックを担い、ビュー層はテンプレートで画面を生成し、コントローラ層がリクエストとレスポンスを処理します。「設定より規約」を重視する設計で、素早く製品を作って改善を続けられます。 対象ユーザー:Ruby でデータベース型 Web アプリを素早く開発したいチームや個人開発者。GitHub では 5.9 万を超えるスターを集めています。
정의: Ruby on Rails는 Ruby로 작성된 풀스택 웹 애플리케이션 프레임워크로, 모델-뷰-컨트롤러(MVC) 패턴에 따라 앱을 구성하며 데이터베이스 기반 웹 앱에 필요한 구성 요소를 모두 갖추고 있습니다. 핵심 기능: 모델 계층은 Active Record가 데이터베이스 테이블을 객체로 매핑해 비즈니스 로직을 담당하고, 뷰 계층은 템플릿으로 화면을 만들며, 컨트롤러 계층은 요청과 응답을 처리합니다. '설정보다 관례'를 중시하는 설계 덕분에 제품을 빠르게 만들고 계속 개선할 수 있습니다. 추천 대상: Ruby로 데이터베이스 기반 웹 앱을 빠르게 개발하려는 팀과 개인 개발자. GitHub에서 5.9만 개가 넘는 스타를 받았습니다.
What it is: Ruby on Rails is a full-stack web application framework written in Ruby. It follows the Model-View-Controller (MVC) pattern and includes everything needed to build database-backed web applications. Key features: The model layer, built on Active Record, maps database rows to objects enriched with business logic; the view layer renders pages from templates; and the controller layer handles requests and responses. Its convention-over-configuration design helps teams ship products quickly and keep iterating. Who it's for: Teams and solo developers who want to build database-driven web apps fast with Ruby. It has over 59,000 stars on GitHub.
README · 详细文档
来源 · 查看原文
Welcome to Rails
What's Rails?
Rails is a web application framework that includes everything needed to create database-backed web applications according to the Model-View-Controller (MVC) pattern.
Understanding the MVC pattern is key to understanding Rails. MVC divides your application into three layers: Model, View, and Controller, each with a specific responsibility.
Model layer
The Model layer represents the domain model (such as Account, Product, Person, Post, etc.) and encapsulates the business logic specific to your application. In Rails, database-backed model classes are derived from ActiveRecord::Base. Active Record allows you to present the data from database rows as objects and embellish these data objects with business logic methods. Although most Rails models are backed by a database, models can also be ordinary Ruby classes, or Ruby classes that implement a set of interfaces as provided by the Active Model module.
View layer
The View layer is composed of "templates" that are responsible for providing appropriate representations of your application's resources. Templates can come in a variety of formats, but most view templates are HTML with embedded Ruby code (ERB files). Views are typically rendered to generate a controller response or to generate the body of an email. In Rails, View generation is handled by Action View.
Controller layer
The Controller layer is responsible for handling incoming HTTP requests and providing a suitable response. Usually, this means returning HTML, but Rails controllers can also generate XML, JSON, PDFs, mobile-specific views, and more. Controllers load and manipulate models, and render view templates in order to generate the appropriate HTTP response. In Rails, incoming requests are routed by Action Dispatch to an appropriate controller, and controller classes are derived from ActionController::Base. Action Dispatch and Action Controller are bundled together in Action Pack.
Frameworks and libraries
Active Record, Active Model, Action Pack, and Action View can each be used independently outside Rails.
In addition to that, Rails also comes with:
- Action Mailer, a library to generate and send emails
- Action Mailbox, a library to receive emails within a Rails application
- Active Job, a framework for declaring jobs and making them run on a variety of queuing backends
- Action Cable, a framework to integrate WebSockets with a Rails application
- Active Storage, a library to attach cloud and local files to Rails applications
- Action Text, a library to handle rich text content
- Active Support, a collection of utility classes and standard library extensions that are useful for Rails, and may also be used independently outside Rails
Getting Started
- Install Rails at the command prompt if you haven't yet:
$ gem install rails
- At the command prompt, create a new Rails application:
$ rails new myapp
where "myapp" is the application name.
- Change directory to
myappand start the web server:
$ cd myapp
$ bin/rails server
Run with --help or -h for options.
- Go to
http://localhost:3000and you'll see the Rails bootscreen with your Rails and Ruby versions.
- Follow the guidelines to start developing your application. You may find
the following resources handy: Getting Started with Rails Ruby on Rails Guides * The API Documentation
Contributing
We encourage you to contribute to Ruby on Rails! Please check out the Contributing to Ruby on Rails guide for guidelines about how to proceed. Join us!
Trying to report a possible security vulnerability in Rails? Please check out our security policy for guidelines about how to proceed.
Everyone interacting in Rails and its sub-projects' codebases, issue trackers, chat rooms, and mailing lists is expected to follow the Rails code of conduct.
License
Ruby on Rails is released under the MIT License.