README.md 4.9 KB
Newer Older
1
# Welcome to Rails
2

T
TomSpencerLondon 已提交
3
## What's Rails?
F
Felipe Tovar 已提交
4

5
Rails is a web-application framework that includes everything needed to
6
create database-backed web applications according to the
7
[Model-View-Controller (MVC)](https://en.wikipedia.org/wiki/Model-view-controller)
8 9 10
pattern.

Understanding the MVC pattern is key to understanding Rails. MVC divides your
X
Xavier Noria 已提交
11
application into three layers: Model, View, and Controller, each with a specific responsibility.
12

F
Felipe Tovar 已提交
13 14 15
## Model layer

The _**Model layer**_ represents the domain model (such as Account, Product,
X
Xavier Noria 已提交
16
Person, Post, etc.) and encapsulates the business logic specific to
17
your application. In Rails, database-backed model classes are derived from
F
Felipe Tovar 已提交
18
`ActiveRecord::Base`. [Active Record](activerecord/README.rdoc) allows you to present the data from
19
database rows as objects and embellish these data objects with business logic
F
Felipe Tovar 已提交
20
methods.
21 22
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
F
Felipe Tovar 已提交
23 24 25
the [Active Model](activemodel/README.rdoc) module.

## Controller layer
26

F
Felipe Tovar 已提交
27
The _**Controller layer**_ is responsible for handling incoming HTTP requests and
R
Rifatul Islam Chayon 已提交
28
providing a suitable response. Usually, this means returning HTML, but Rails controllers
E
Eugene Gilburg 已提交
29 30 31 32
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
F
Felipe Tovar 已提交
33
are bundled together in [Action Pack](actionpack/README.rdoc).
E
Eugene Gilburg 已提交
34

F
Felipe Tovar 已提交
35 36 37
## View layer

The _**View layer**_ is composed of "templates" that are responsible for providing
E
Eugene Gilburg 已提交
38 39
appropriate representations of your application's resources. Templates can
come in a variety of formats, but most view templates are HTML with embedded
R
Rifatul Islam Chayon 已提交
40
Ruby code (ERB files). Views are typically rendered to generate a controller response 
F
Felipe Tovar 已提交
41 42 43
or to generate the body of an email. In Rails, View generation is handled by [Action View](actionview/README.rdoc).

## Frameworks and libraries
E
Eugene Gilburg 已提交
44

F
Felipe Tovar 已提交
45 46
[Active Record](activerecord/README.rdoc), [Active Model](activemodel/README.rdoc), [Action Pack](actionpack/README.rdoc), and [Action View](actionview/README.rdoc) can each be used independently outside Rails.
In addition to that, Rails also comes with [Action Mailer](actionmailer/README.rdoc), a library
47 48
to generate and send emails; [Action Mailbox](actionmailbox/README.md), a library to receive emails within a Rails application;
[Active Job](activejob/README.md), a framework for declaring jobs and making them run on a variety of queuing
F
Felipe Tovar 已提交
49 50
backends; [Action Cable](actioncable/README.md), a framework to
integrate WebSockets with a Rails application; [Active Storage](activestorage/README.md), a library to attach cloud
51
and local files to Rails applications; [Action Text](actiontext/README.md), a library to handle rich text content;
F
Felipe Tovar 已提交
52
and [Active Support](activesupport/README.rdoc), a collection
53 54
of utility classes and standard library extensions that are useful for Rails,
and may also be used independently outside Rails.
55 56 57 58 59

## Getting Started

1. Install Rails at the command prompt if you haven't yet:

60
        $ gem install rails
61 62 63

2. At the command prompt, create a new Rails application:

64
        $ rails new myapp
65 66 67 68 69

   where "myapp" is the application name.

3. Change directory to `myapp` and start the web server:

70
        $ cd myapp
71
        $ bin/rails server
72 73 74

   Run with `--help` or `-h` for options.

X
Xavier Noria 已提交
75
4. Go to `http://localhost:3000` and you'll see:
76
"Yay! You’re on Rails!"
77 78 79

5. Follow the guidelines to start developing your application. You may find
   the following resources handy:
80 81
    * [Getting Started with Rails](https://guides.rubyonrails.org/getting_started.html)
    * [Ruby on Rails Guides](https://guides.rubyonrails.org)
82
    * [The API Documentation](https://api.rubyonrails.org)
83 84 85

## Contributing

S
schneems 已提交
86 87
[![Code Triage Badge](https://www.codetriage.com/rails/rails/badges/users.svg)](https://www.codetriage.com/rails/rails)

88
We encourage you to contribute to Ruby on Rails! Please check out the
89
[Contributing to Ruby on Rails guide](https://edgeguides.rubyonrails.org/contributing_to_ruby_on_rails.html) for guidelines about how to proceed. [Join us!](https://contributors.rubyonrails.org)
90

91
Trying to report a possible security vulnerability in Rails? Please
92
check out our [security policy](https://rubyonrails.org/security/) for
93 94
guidelines about how to proceed.

95
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](https://rubyonrails.org/conduct/).
96

97 98
## Code Status

M
Matthew Draper 已提交
99
[![Build Status](https://badge.buildkite.com/ab1152b6a1f6a61d3ea4ec5b3eece8d4c2b830998459c75352.svg?branch=master)](https://buildkite.com/rails/rails)
100 101 102

## License

103
Ruby on Rails is released under the [MIT License](https://opensource.org/licenses/MIT).