Skip to main content Link Search Menu Expand Document (external link)

Ruby on Rails 指南

这是基于 Ruby on Rails 7 的指南。更早期版本可查看……

从这里开始

Rails 起步

安装 Rails 和创建您的第一个应用程序时应该知道的那些事儿。

模型(Model)

Active Record 基础

Active Record 使您的模型与应用程序的数据库互操作,本文您可以学习到 Active Record 模型起步知识和如何将数据持久化到数据库中。

Active Record 迁移

迁移是 Active Record 的一大功能——记录您的数据库结构进化过程。与使用纯 SQL 编写数据库结构修改不一样,迁移允许您使用 Ruby DSL 来描述数据库表的修改过程。

Active Record 验证

验证用于确保有效数据保存到数据库。本文教您在对象进入数据库之前如何使用 Active Record 的验证功能验证对象状态。

Active Record 回调

回调(Callback)让一个对象不论是在创建、更新还是销毁时都可 写出可执行代码成为可能。本文教您如何利用 Active Record 对象 功能进入和调用一个对象的生命周期的各个阶段。

Active Record 关联

在 Active Record 中,关联就是两个 Active Record 对象之间的连接。 本文内容覆盖了 Active Record 提供的所有关联。

Active Record 查询界面

与使用原生 SQL 检索数据库数据不同的是,Active Record 提供了更好的 方式来执行相关操作。本文内容覆盖了利用 Active Record 从数据库检索 数据的不同方式。

Active Model 基础

编纂中……

Active Model 允许您创建一个与 Action Pack 集成的简单的 Ruby 对象,但 不需要 Active Record 的数据库持久化。Active Model 也能帮助构建用于 Rails 框架以外的定制 ORM。本文提供给您所有使用 Active Model 类需要的知识。

视图(View)

Action View 概览

编纂中……

Action View 应用程序的反馈——生成基于 HTML 的反馈。本文提供 Action View 的介绍。

Layout 和 Rails 渲染

本文覆盖了 Action Controller 和 Action View 基本布局(layout)功能, 包括渲染和转接、使用 content_for 块和使用局部模板等。

Action View 辅助(Helper)

编纂中……

Action View has helpers for handling everything from formatting dates and linking to images, to sanitizing and localizing content. This guide introduces a few of the more common Action View helpers.

Action View 表单(Form)辅助( Helper)

HTML forms can quickly become tedious to write and maintain because of the need to handle form control naming and its numerous attributes. Rails does away with this complexity by providing view helpers for generating form markup.

控制器(Controller)

Action Controller 概览

Action Controller 在 Rails 中是 Web 请求的核心。本文内容涵盖了控制器如何工作 和它们如何与您的应用程序的循环请求配合工作等。它包含会话(session)、过滤器(filter)、 cookie、数据流(data streaming),以及如何处理因为请求引起的意外问题(exception)等等。

Rails 路由(Route)详解

The Rails router recognizes URLs and dispatches them to a controller’s action. This guide covers the user-facing features of Rails routing. If you want to understand how to use routing in your own Rails applications, start here.

其他组件(Component)

Active Support 核心扩展(Core Extension)

Active Support provides Ruby language extensions and utilities. It enriches the Ruby language for the development of Rails applications, and for the development of Ruby on Rails itself.

Action Mailer 基础

This guide provides you with all you need to get started in sending emails from your application, and many internals of Action Mailer.

Action Mailbox 基础

编纂中……

This guide describes how to use Action Mailbox to receive emails.

Action Text 概览

编纂中……

This guide describes how to use Action Text to handle rich text content.

Active Job 基础

Active Job is a framework for declaring background jobs and making them run on a variety of queuing backends. This guide provides you with all you need to get started creating, enqueuing, and executing background jobs.

Active Storage 概览

Active Storage facilitates uploading files to a cloud storage service, transforming uploads and extracting metadata. This guide covers how to attach files to your Active Record models.

Action Cable 概览

Action Cable integrates WebSockets with the rest of your Rails application. It allows for real-time features to be written in Ruby in the same style and form as the rest of your Rails application. This guide explains how Action Cable works, and how to use WebSockets to create real-time features.

Webpacker

This guide will show you how to install and use Webpacker to package JavaScript, CSS, and other assets for the client-side of your Rails application.

深入探究

Rails 国际化(I18n)API

This guide covers how to add internationalization to your applications. Your application will be able to translate content to different languages, change pluralization rules, use correct date formats for each country, and so on.

Rails 应用程序的测试

This is a rather comprehensive guide to the various testing facilities in Rails. It covers everything from ‘What is a test?’ to Integration Testing. Enjoy.

Rails 应用程序的安全

This guide describes common security problems in web applications and how to avoid them with Rails.

Rails 应用程序的错误报告

This guide introduces ways to manage exceptions that occur in Ruby on Rails applications.

Rails 应用程序的调试

This guide describes how to debug Rails applications. It covers the different ways of achieving this and how to understand what is happening “behind the scenes” of your code.

Rails 应用程序的配置

This guide covers the basic configuration settings for a Rails application.

Rails 命令行

There are a few commands that are absolutely critical to your everyday usage of Rails. This guide covers the command line tools provided by Rails.

Rails 的 Asset Pipeline

The asset pipeline provides a framework to concatenate and minify or compress JavaScript, CSS and image assets. It also adds the ability to write these assets in other languages and pre-processors such as CoffeeScript, Sass, and ERB.

在 Rails 中使用 JavaScript

This guide explains how to use import maps or jsbundling-rails to include JavaScript in Rails applications, and covers the basics of working with Turbo in Rails.

Rails 的初始化

编纂中……

This guide explains the internals of the initialization process in Rails. It is an extremely in-depth guide and recommended for advanced Rails developers.

常量的自动加载和重载

This guide documents how autoloading and reloading constants work (Zeitwerk mode).

传统到 Zeitwerk 问题集锦

This guide documents how to migrate Rails applications from classic to zeitwerk mode.

Rails 缓存概览

This guide is an introduction to speeding up your Rails application with caching.

Active Support Instrumentation

编纂中……

This guide explains how to use the instrumentation API inside of Active Support to measure events inside of Rails and other Ruby code.

用 Rails 开发仅提供 API 的应用程序

This guide explains how to effectively use Rails to develop a JSON API application.

Active Record 和 PostgreSQL

编纂中……

This guide covers PostgreSQL specific usage of Active Record.

用 Active Record 操作多数据库

This guide covers using multiple databases in your application.

Active Record 加密

编纂中……

This guide covers encrypting your database information using Active Record.

扩展 Rails

Rails 插件创建的基础知识

编纂中……

This guide covers how to build a plugin to extend the functionality of Rails.

Rails on Rack

This guide covers Rails integration with Rack and interfacing with other Rack components.

创建和定制 Rails 生成器及模板

This guide covers the process of adding a brand new generator to your extension or providing an alternative to an element of a built-in Rails generator (such as providing alternative test stubs for the scaffold generator).

Getting Started with Engines

编纂中……

Engines can be considered miniature applications that provide additional functionality to their host applications. In this guide you will learn how to create your own engine and integrate it with a host application.

Rails 中的线程和代码执行

编纂中……

This guide describes the considerations needed and tools available when working directly with concurrency in a Rails application.

贡献

为 Ruby on Rails 做贡献

Rails is not “someone else’s framework”. This guide covers a variety of ways that you can get involved in the ongoing development of Rails.

API 文档纲要

This guide documents the Ruby on Rails API documentation guidelines.

指南纲要

This guide documents the Ruby on Rails guides guidelines.

政策

维护政策

What versions of Ruby on Rails are currently supported, and when to expect new versions.

版本发布注记

升级 Ruby on Rails

This guide provides steps to be followed when you upgrade your applications to a newer version of Ruby on Rails.

Version 7.1 - ?

编纂中……

Release notes for Rails 7.1.

Version 7.0 - December 2021

Release notes for Rails 7.0.

Version 6.1 - December 2020

Release notes for Rails 6.1.

Version 6.0 - August 2019

Release notes for Rails 6.0.

Version 5.2 - April 2018

Release notes for Rails 5.2.

Version 5.1 - April 2017

Release notes for Rails 5.1.

Version 5.0 - June 2016

Release notes for Rails 5.0.

Version 4.2 - December 2014

Release notes for Rails 4.2.

Version 4.1 - April 2014

Release notes for Rails 4.1.

Version 4.0 - June 2013

Release notes for Rails 4.0.

Version 3.2 - January 2012

Release notes for Rails 3.2.

Version 3.1 - August 2011

Release notes for Rails 3.1.

Version 3.0 - August 2010

Release notes for Rails 3.0.

Version 2.3 - March 2009

Release notes for Rails 2.3.

Version 2.2 - November 2008

Release notes for Rails 2.2.