Skip to content

Commit 71d3e59

Browse files
committed
split out separate 'rails architecture' page
1 parent 4f313de commit 71d3e59

File tree

2 files changed

+60
-46
lines changed

2 files changed

+60
-46
lines changed

sites/en/intro-to-rails/creating_a_migration.step

Lines changed: 11 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,24 @@ goals {
44

55
message "The suggestotron has a list of topics that people can vote on. We'll store our topics in the database. In this step you'll do the following:"
66

7-
goal "Create a database table for topics with a title and a description"
7+
goal "Create a a simple *Table* in the database for topics with a title and a description"
8+
goal "Automatically generate the corresponding *Scaffold* in Rails (namely, the *Model*, the *View*, and the *Controller*)."
89

9-
message "In this step we'll learn a bit about Rails architecture. By the end of this step you should understand the following concepts:"
10-
11-
ul {
12-
li "A record"
13-
li "Model"
14-
li "View"
15-
li "Controller"
16-
}
1710
}
1811

1912
steps {
2013

21-
2214
step {
2315
console "rails generate scaffold topic title:string description:text"
2416
message <<-MARKDOWN
2517
* `generate scaffold` tells rails to create everything necessary to get up and running with topics.
2618
* `topic` tells rails the name of the new model.
27-
* `title:string` says that topics have a title, which is a string.
28-
* `description:text` says that topics have a description which is a "text". (We're befuddled by the difference too.)
19+
* `title:string` says that topics have a title, which is a "string".
20+
* `description:text` says that topics have a description which is a "text". (What's the difference between "string" and "text"? Basically "text" is for strings that might be very long.)
21+
2922
MARKDOWN
30-
message "If you want, take some time to poke around the files listed in this step."
23+
message "If you want, take some time to poke around the files listed in this step. You can learn about them in the [Rails Architecture](rails_architecture) page."
24+
link "rails_architecture"
3125
}
3226

3327
step {
@@ -40,43 +34,14 @@ explanation {
4034

4135
h2 "Rake"
4236
message <<-MARKDOWN
43-
`rake` _(Ruby Make)_ is a tool that allows you to run small Ruby programs (**tasks**) that you use often in your application. Here, `rake db:migrate` is a task provided by the Rails framework.
44-
45-
You can run `rake -T` to see a list of all the `rake` commands your app currently responds to, along with a short description of each task.
46-
MARKDOWN
47-
48-
h2 "Explaining Rails architecture and its relation to the database"
49-
50-
img src: "img/mvc.png", alt: "MVC"
37+
`rake` _(ruby make)_ is a tool that allows you to run small Ruby programs (**tasks**) that you use often in your application.
5138

52-
message "Rails implements a very specific notion of the **Model/View/Controller** pattern, which guides how you structure your web applications."
39+
Here, `rake db:migrate` is a task provided by the Rails framework. It creates a bunch of new files, including a *migration*, a *model*, a *view*, and a *controller*.
5340

54-
h3 "Model"
55-
message <<-MARKDOWN
56-
* For all the Models we create in RailsBridge, Model objects have a corresponding record in the the database. The name of the table in the database is the plural version of the Model's class name. For example, if the Model is called 'Duck', it will automatically query or write to the 'ducks' table in the database.
57-
* Methods internal to Rails make it easy to automatically write records to the the database and query the database to get the records again later.
58-
* The Model is a bridge between the database and your application's code.
5941
MARKDOWN
6042

61-
h3 "View"
62-
message <<-MARKDOWN
63-
* The View generates the HTML that will be displayed in the browser.
64-
* View files are written in ERB, a templating language. It contains HTML with Ruby code embedded in it. The ruby variables in the view stand as placeholders for content that will be filled in when a user requests the page.
65-
* (There are several other templating languages available, but in RailsBridge we always stick to ERB.)
66-
MARKDOWN
67-
68-
h3 "Controller"
69-
message <<-MARKDOWN
70-
* Controllers pass Ruby objects between the Models and the Views.
71-
* Each url corresponds to a specific method in a Controller.
72-
* After this step, when you visit any page in your application, that request will be handled by a method in a Controller.
73-
MARKDOWN
74-
75-
76-
message <<-MARKDOWN
77-
When Models, Views and Controllers are all put together, they follow a pattern: Given a url, Rails will look up which Controller method (also called an "Action") to use. The Controller Action will use methods in a corresponding Model. The Model will need to read or write to the database, and return an object containing that data to the Controller. The Controller will take that object and pass it to the View. (Actions normally have a corresponding View file, and Rails will automatically find and use that file.)
78-
Models, Views and Controllers each have specific jobs. Separating responsibilities like this make it easier to develop, especially as it gets bigger. (When each file has a clear responsibility it's easier to fix problems and add new features.)
79-
MARKDOWN
43+
tip "You can run `rake -T` to see a list of all the `rake` commands your app currently responds to, along with a short description of each task."
8044
}
8145

46+
8247
next_step "CRUD_with_scaffolding"
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
goals {
2+
3+
goal "Create a database table for topics with a title and a description"
4+
5+
message "In this step we'll learn a bit about Rails architecture. By the end of this step you should understand the following concepts:"
6+
7+
ul {
8+
li "Table"
9+
li "Model"
10+
li "View"
11+
li "Controller"
12+
}
13+
}
14+
15+
explanation {
16+
17+
h2 "Rails architecture and its relation to the database"
18+
19+
img src: "img/mvc.png", alt: "MVC"
20+
21+
message "Rails implements a very specific notion of the **Model/View/Controller** pattern, which guides how you structure your web applications."
22+
23+
h3 "Model"
24+
message <<-MARKDOWN
25+
* For all the Models we create in RailsBridge, Model objects have a corresponding record in the the database. The name of the table in the database is the plural version of the Model's class name. For example, if the Model is called 'Duck', it will automatically query or write to the 'ducks' table in the database.
26+
* Methods internal to Rails make it easy to automatically write records to the the database and query the database to get the records again later.
27+
* The Model is a bridge between the database and your application's code.
28+
MARKDOWN
29+
30+
h3 "View"
31+
message <<-MARKDOWN
32+
* The View generates the HTML that will be displayed in the browser.
33+
* View files are written in ERB, a templating language. It contains HTML with Ruby code embedded in it. The ruby variables in the view stand as placeholders for content that will be filled in when a user requests the page.
34+
* (There are several other templating languages available, but in RailsBridge we always stick to ERB.)
35+
MARKDOWN
36+
37+
h3 "Controller"
38+
message <<-MARKDOWN
39+
* Controllers pass Ruby objects between the Models and the Views.
40+
* Each url corresponds to a specific method in a Controller.
41+
* After this step, when you visit any page in your application, that request will be handled by a method in a Controller.
42+
MARKDOWN
43+
44+
message <<-MARKDOWN
45+
When Models, Views and Controllers are all put together, they follow a pattern: Given a URL, Rails will look up which Controller method (also called an "Action") to use. The Controller Action will use methods in a corresponding Model. The Model will need to read or write to the database, and return an object containing that data to the Controller. The Controller will take that object and pass it to the View. (Actions normally have a corresponding View file, and Rails will automatically find and use that file.)
46+
47+
Models, Views and Controllers each have specific jobs. Separating responsibilities like this make it easier to develop, especially as it gets bigger. (When each file has a clear responsibility it's easier to fix problems and add new features.)
48+
MARKDOWN
49+
}

0 commit comments

Comments
 (0)