You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* `generate scaffold` tells rails to create everything necessary to get up and running with topics.
26
18
* `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
+
29
22
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"
31
25
}
32
26
33
27
step {
@@ -40,43 +34,14 @@ explanation {
40
34
41
35
h2 "Rake"
42
36
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.
51
38
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*.
53
40
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.
59
41
MARKDOWN
60
42
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."
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.)
0 commit comments