rails / rails
rails / rails
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.
欢迎来到 Rails。什么是 Rails?Rails 是一个 Web 应用程序框架,它包含了根据模型-视图-控制器(MVC)模式创建数据库驱动的 Web 应用程序所需的一切。理解 MVC 模式是理解 Rails 的关键。MVC 将您的应用程序分为三个层:模型、视图和控制器,每一层都有特定的职责。
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.
模型层:模型层代表领域模型(例如账户、产品、人员、文章等),并封装了特定于您应用程序的业务逻辑。在 Rails 中,数据库驱动的模型类派生自 ActiveRecord::Base。Active Record 允许您将数据库行中的数据呈现为对象,并使用业务逻辑方法来修饰这些数据对象。虽然大多数 Rails 模型由数据库支持,但模型也可以是普通的 Ruby 类,或者是实现了 Active Model 模块所提供的一组接口的 Ruby 类。
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.
视图层:视图层由“模板”组成,负责提供应用程序资源的适当表示。模板可以有多种格式,但大多数视图模板是带有嵌入式 Ruby 代码的 HTML(ERB 文件)。视图通常被渲染以生成控制器响应或生成电子邮件的正文。在 Rails 中,视图生成由 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.
控制器层:控制器层负责处理传入的 HTTP 请求并提供合适的响应。通常,这意味着返回 HTML,但 Rails 控制器也可以生成 XML、JSON、PDF、移动设备专用视图等。控制器加载并操作模型,并渲染视图模板以生成适当的 HTTP 响应。在 Rails 中,传入的请求由 Action Dispatch 路由到适当的控制器,控制器类派生自 ActionController::Base。Action Dispatch 和 Action Controller 被捆绑在 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
框架和库:Active Record、Active Model、Action Pack 和 Action View 都可以独立于 Rails 使用。除此之外,Rails 还附带了:Action Mailer(用于生成和发送电子邮件的库)、Action Mailbox(用于在 Rails 应用程序中接收电子邮件的库)、Active Job(用于声明作业并使其在各种队列后端上运行的框架)、Action Cable(用于将 WebSockets 与 Rails 应用程序集成的框架)、Active Storage(用于将云文件和本地文件附加到 Rails 应用程序的库)、Action Text(用于处理富文本内容的库)、Active Support(对 Rails 有用的实用程序类和标准库扩展的集合,也可以独立于 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 myapp and start the web server: $ cd myapp $ bin/rails server Run with —help or -h for options. Go to http://localhost:3000 and 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
入门:如果您还没有安装 Rails,请在命令提示符下安装:$ gem install rails。在命令提示符下,创建一个新的 Rails 应用程序:$ rails new myapp,其中“myapp”是应用程序名称。切换目录到 myapp 并启动 Web 服务器:$ cd myapp $ bin/rails server。运行 —help 或 -h 查看选项。访问 http://localhost:3000,您将看到显示您的 Rails 和 Ruby 版本的 Rails 启动屏幕。按照指南开始开发您的应用程序。您可能会发现以下资源很有用:Rails 入门、Ruby on Rails 指南、API 文档。
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.
贡献:我们鼓励您为 Ruby on Rails 做出贡献!请查看“为 Ruby on Rails 做出贡献”指南,了解如何进行。加入我们!试图报告 Rails 中可能存在的安全漏洞?请查看我们的安全策略以获取有关如何进行的指南。每个在 Rails 及其子项目的代码库、问题跟踪器、聊天室和邮件列表中进行交互的人都应遵守 Rails 行为准则。
License Ruby on Rails is released under the MIT License.
许可证:Ruby on Rails 在 MIT 许可证下发布。