Skip to content

Commit c5784a1

Browse files
committed
+ MVC page
1 parent 264d6c4 commit c5784a1

File tree

7 files changed

+84
-34
lines changed

7 files changed

+84
-34
lines changed
106 KB
Loading
111 KB
Loading
Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
type: lesson
33
title: Creating your first Rails app
4+
editor: false
45
custom:
56
shell:
67
workdir: "/workspace"
@@ -31,37 +32,3 @@ After your new application is created, switch to its directory:
3132
```bash
3233
$ cd store
3334
```
34-
35-
### Directory Structure
36-
37-
Let's take a quick glance at the files and directories that are included in a
38-
new Rails application. You can open this folder in your code editor or run
39-
`ls -la` in your terminal to see the files and directories.
40-
| File/Folder | Purpose |
41-
|------------|---------|
42-
| app/ | Contains the controllers, models, views, helpers, mailers, jobs, and assets for your application. **You'll focus mostly on this folder for the remainder of this guide.** |
43-
| bin/ | Contains the `rails` script that starts your app and can contain other scripts you use to set up, update, deploy, or run your application. |
44-
| config/ | Contains configuration for your application's routes, database, and more. This is covered in more detail in [Configuring Rails Applications](configuring.html). |
45-
| config.ru | [Rack](https://rack.github.io) configuration for Rack-based servers used to start the application. |
46-
| db/ | Contains your current database schema, as well as the database migrations. |
47-
| Dockerfile | Configuration file for Docker. |
48-
| Gemfile | These files allow you to specify what gem dependencies are needed for your Rails application. These files are used by the [Bundler](https://bundler.io) gem. |
49-
| Gemfile.lock | The lock file that ensures consistent gem versions across different environments. |
50-
| lib/ | Extended modules for your application. |
51-
| log/ | Application log files. |
52-
| public/ | Contains static files and compiled assets. When your app is running, this directory will be exposed as-is. |
53-
| Rakefile | This file locates and loads tasks that can be run from the command line. The task definitions are defined throughout the components of Rails. Rather than changing `Rakefile`, you should add your own tasks by adding files to the `lib/tasks` directory of your application. |
54-
| README.md | This is a brief instruction manual for your application. You should edit this file to tell others what your application does, how to set it up, and so on. |
55-
| script/ | Contains one-off or general purpose [scripts](https://github.com/rails/rails/blob/main/railties/lib/rails/generators/rails/script/USAGE) and [benchmarks](https://github.com/rails/rails/blob/main/railties/lib/rails/generators/rails/benchmark/USAGE). |
56-
| storage/ | Contains SQLite databases and Active Storage files for Disk Service. This is covered in [Active Storage Overview](active_storage_overview.html). |
57-
| test/ | Unit tests, fixtures, and other test apparatus. These are covered in [Testing Rails Applications](testing.html). |
58-
| tmp/ | Temporary files (like cache and pid files). |
59-
| vendor/ | A place for all third-party code. In a typical Rails application this includes vendored gems. |
60-
| .dockerignore | This file tells Docker which files it should not copy into the container. |
61-
| .gitattributes | This file defines metadata for specific paths in a Git repository. This metadata can be used by Git and other tools to enhance their behavior. See the [gitattributes documentation](https://git-scm.com/docs/gitattributes) for more information. |
62-
| .git/ | Contains Git repository files. |
63-
| .github/ | Contains GitHub specific files. |
64-
| .gitignore | This file tells Git which files (or patterns) it should ignore. See [GitHub - Ignoring files](https://help.github.com/articles/ignoring-files) for more information about ignoring files. |
65-
| .kamal/ | Contains Kamal secrets and deployment hooks. |
66-
| .rubocop.yml | This file contains the configuration for RuboCop. |
67-
| .ruby-version | This file contains the default Ruby version. |
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "../../../../../templates/rails-new"
3+
}

src/content/tutorial/2-rails-new/3-directory-structure/_files/workspace/.keep

Whitespace-only changes.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
type: lesson
3+
title: Creating your first Rails app
4+
editor: false
5+
custom:
6+
shell:
7+
workdir: "/workspace/store"
8+
---
9+
10+
Directory Structure
11+
-------------------
12+
13+
Let's take a quick glance at the files and directories that are included in a
14+
new Rails application.
15+
16+
Go to the terminal (to your right) and run the following command:
17+
18+
```bash
19+
$ ls -la
20+
```
21+
22+
Here is what you should see in the output:
23+
24+
:::info
25+
Items marks with † are related to local development environment, deployment and CI, and, thus, missing in the web version.
26+
:::
27+
28+
| File/Folder | Purpose |
29+
|------------|---------|
30+
| app/ | Contains the controllers, models, views, helpers, mailers, jobs, and assets for your application. **You'll focus mostly on this folder for the remainder of this guide.** |
31+
| bin/ | Contains the `rails` script that starts your app and can contain other scripts you use to set up, update, deploy, or run your application. |
32+
| config/ | Contains configuration for your application's routes, database, and more. This is covered in more detail in [Configuring Rails Applications](configuring.html). |
33+
| config.ru | [Rack](https://rack.github.io) configuration for Rack-based servers used to start the application. |
34+
| db/ | Contains your current database schema, as well as the database migrations. |
35+
| Dockerfile† | Configuration file for Docker. |
36+
| Gemfile | These files allow you to specify what gem dependencies are needed for your Rails application. These files are used by the [Bundler](https://bundler.io) gem. |
37+
| Gemfile.lock† | The lock file that ensures consistent gem versions across different environments. |
38+
| lib/ | Extended modules for your application. |
39+
| log/ | Application log files. |
40+
| public/ | Contains static files and compiled assets. When your app is running, this directory will be exposed as-is. |
41+
| Rakefile | This file locates and loads tasks that can be run from the command line. The task definitions are defined throughout the components of Rails. Rather than changing `Rakefile`, you should add your own tasks by adding files to the `lib/tasks` directory of your application. |
42+
| README.md | This is a brief instruction manual for your application. You should edit this file to tell others what your application does, how to set it up, and so on. |
43+
| script/ | Contains one-off or general purpose [scripts](https://github.com/rails/rails/blob/main/railties/lib/rails/generators/rails/script/USAGE) and [benchmarks](https://github.com/rails/rails/blob/main/railties/lib/rails/generators/rails/benchmark/USAGE). |
44+
| storage/ | Contains SQLite databases and Active Storage files for Disk Service. This is covered in [Active Storage Overview](active_storage_overview.html). |
45+
| test/ | Unit tests, fixtures, and other test apparatus. These are covered in [Testing Rails Applications](testing.html). |
46+
| tmp/ | Temporary files (like cache and pid files). |
47+
| vendor/ | A place for all third-party code. In a typical Rails application this includes vendored gems. |
48+
| .dockerignore† | This file tells Docker which files it should not copy into the container. |
49+
| .gitattributes† | This file defines metadata for specific paths in a Git repository. This metadata can be used by Git and other tools to enhance their behavior. See the [gitattributes documentation](https://git-scm.com/docs/gitattributes) for more information. |
50+
| .git/† | Contains Git repository files. |
51+
| .github/† | Contains GitHub specific files. |
52+
| .gitignore† | This file tells Git which files (or patterns) it should ignore. See [GitHub - Ignoring files](https://help.github.com/articles/ignoring-files) for more information about ignoring files. |
53+
| .kamal/† | Contains Kamal secrets and deployment hooks. |
54+
| .rubocop.yml† | This file contains the configuration for RuboCop. |
55+
| .ruby-version | This file contains the default Ruby version. |
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
type: lesson
3+
title: MVC Basics
4+
editor: false
5+
terminal: false
6+
---
7+
8+
Model-View-Controller Basics
9+
----------------------------
10+
11+
Rails code is organized using the Model-View-Controller (MVC) architecture. With
12+
MVC, we have three main concepts where the majority of our code lives:
13+
14+
* Model - Manages the data in your application. Typically, your database tables.
15+
* View - Handles rendering responses in different formats like HTML, JSON, XML,
16+
etc.
17+
* Controller - Handles user interactions and the logic for each request.
18+
19+
<picture class="flowdiagram">
20+
<source srcset="/images/getting_started/mvc_architecture_dark.jpg" media="(prefers-color-scheme:dark)"/>
21+
<img src="/images/getting_started/mvc_architecture_light.jpg"/>
22+
</picture>
23+
24+
Now that we've got a basic understanding of MVC, let's see how it's used in
25+
Rails.

0 commit comments

Comments
 (0)