Skip to content

Commit e3e6172

Browse files
committed
Merge pull request railsbridge#298 from railsbridge/never-speak-mvc
De-jargon-ify MVC explanation.
2 parents a286d48 + b4a31aa commit e3e6172

File tree

4 files changed

+101
-58
lines changed

4 files changed

+101
-58
lines changed

lib/step.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,11 @@ def goals
170170
end
171171
end
172172

173-
alias_method :goal, :li
173+
def goal *args
174+
li do
175+
message *args
176+
end
177+
end
174178

175179
def site_desc site_name, description
176180
div class: 'site-desc' do
@@ -215,6 +219,7 @@ def tip text = nil, &block
215219

216220
## special
217221

222+
# todo: i18n
218223
TERMINAL_CAPTION = "Type this in the terminal:"
219224
IRB_CAPTION = "Type this in irb:"
220225
RESULT_CAPTION = "Expected result:"

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

Lines changed: 11 additions & 43 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 MVC (Model-View-Controller) 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,40 +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 MVC and Records"
49-
50-
img src: "img/mvc.png", alt: "MVC"
51-
52-
message "Rails implements a very specific notion of the **Model/View/Controller** pattern, which guides how you structure your web applications."
53-
54-
h3 "Model"
55-
message <<-MARKDOWN
56-
* saves data to the database
57-
* accesses data from the database
58-
* bridge between the database and objects
59-
MARKDOWN
37+
`rake` _(ruby make)_ is a tool that allows you to run small Ruby programs (**tasks**) that you use often in your application.
6038

61-
h3 "View"
62-
message <<-MARKDOWN
63-
* display the data for human (or machine) consumption
64-
* webpages are views
65-
MARKDOWN
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*.
6640

67-
h3 "Controller"
68-
message <<-MARKDOWN
69-
* acts as the glue between the models and the views
70-
* combines data from multiple models
71-
* summarizes and filters data
7241
MARKDOWN
7342

74-
message <<-MARKDOWN
75-
In MVC, models, views, and controllers have very specific jobs. Separating responsibilities like this make it easy to maintain and extend rails applications. When responsibilities become muddied it gets much harder to debug issues and add new functionality.
76-
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."
7744
}
7845

46+
7947
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+
}

step_file_reference.md

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,23 @@ Here Docs are especially useful with `message`s since you can just dump in markd
2424
* maintains a count of steps at the same level
2525
* prefixes name with e.g. "Step 1:"
2626

27+
`goals do`
28+
29+
* a titled, formatted list of goals
30+
31+
`goal "text"`
32+
33+
* an individual goal (marked up with \<li\>)
34+
* text can be markdown
35+
36+
`steps do`
37+
38+
* a titled, formatted list of steps
39+
40+
`explanation do`
41+
42+
* a titled, formatted block for a summary of what the student just did
43+
2744
`link "name"`
2845

2946
* links to a step whose file name is `filename`
@@ -38,38 +55,32 @@ Here Docs are especially useful with `message`s since you can just dump in markd
3855
* creates a step which is named "Option 1: foo" instead "Step 1: foo"
3956
* supports nested blocks, which reset the step count again
4057

41-
`verify`
42-
43-
`verify "name"`
44-
45-
* usually contains `console` and `result` notes
46-
* kind of like a step, but doesn't increment the number count
47-
48-
`tip "name"`
49-
50-
* called out in a blue box
51-
* the name is *not* markdown, but is a bold title for the tip box
52-
* content should be inside a nested block
53-
5458
`insert "filename"`
5559

5660
* inserts the contents of one file inside another
5761
* a way to do "partials"
5862
* current limitations:
5963
* only works with `.step` files
6064
* inserted file must be in same directory as inserting file
65+
* prepends an underscore to the file name
6166

6267
## messages
6368

6469
`message "text"`
6570

6671
* makes a paragraph of text anywhere in the document
6772
* the text parameter is passed through a Markdown converter
68-
73+
6974
`important "text"`
7075

7176
* like a message, but called out in a red box
7277

78+
`tip "name" do`
79+
80+
* called out in a blue box
81+
* the name is *not* markdown, but is an optional bold title for the tip box
82+
* content should be inside a nested block
83+
7384
## special
7485

7586
Special elements do *not* format their text as Markdown.
@@ -85,6 +96,16 @@ Special elements do *not* format their text as Markdown.
8596
* indicates that the student should see some output in the terminal
8697
* says "expected result:" and then puts the text in a `pre` block
8798

99+
`verify`
100+
101+
`verify "name"`
102+
103+
* usually contains `console` and `result` notes
104+
* kind of like a step, but doesn't increment the number count
105+
106+
`irb "text"`
107+
108+
* like "console" but indicates that the student should type something into irb
88109

89110

90111
## erector elements

0 commit comments

Comments
 (0)