forked from cherimarie/gdi-rails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass3.html
337 lines (284 loc) · 12.4 KB
/
class3.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Intro to Rails</title>
<meta name="description" content="This is an Intro to Rails course, intended for eventual inclusion in the Girl Develop It Core Curriculum. All material by Cheri Allen, inspired by Railsbridge.
The course is meant to be taught in four two-hour workshops. Each of the slides and practice files are customizable according to the needs of a given class or audience.">
<meta name="author" content="Girl Develop It">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<link rel="stylesheet" href="reveal.js/css/reveal.css">
<link rel="stylesheet" href="reveal.js/css/theme/gdicool.css" id="theme">
<link rel="stylesheet" href="overwrite.css">
<!-- For syntax highlighting -->
<link rel="stylesheet" href="reveal.js/lib/css/light.css">
<!-- dark editor<link rel="stylesheet" href="reveal.js/lib/css/dark.css"> -->
<!-- If use the PDF print sheet so students can print slides-->
<link rel="stylesheet" href="reveal.js/css/print/pdf.css" type="text/css" media="print">
<!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
<script>document.write('<script src="http://' + (location.host || 'localhost').split(':')[0] + ':35729/livereload.js?snipver=1"></' + 'script>')</script>
</head>
<body>
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<!-- Opening slide -->
<section>
<img src = "images/gdi_logo_badge.png" alt="Girl Develop It Logo">
<h3>Intro to Rails</h3>
<p>slides: http://cherimarie.github.io/gdi-rails</p>
</section>
<!-- Intro -->
<section>
<h3>Welcome!</h3>
<div class = "left-align">
<p>Girl Develop It is here to provide affordable and accessible programs to learn software through mentorship and hands-on instruction.</p>
<p class ="green">Some "rules"</p>
<ul>
<li>We are here for you!</li>
<li>Every question is important</li>
<li>Help each other</li>
<li>Have fun</li>
</ul>
</div>
</section>
<section>
<h3>What we will cover today</h3>
<ul>
<li>Homework Review</li>
<li>Controllers</li>
<li>Routes</li>
<li>Views</li>
</ul>
</section>
<section>
<h3>Homework Review</h3>
<h5>Rails Console</h5>
<ol>
<li>Rails for Zombies</li>
<ul>
<li>Problems?</li>
</ul>
<li>Rails Console Experimentation</li>
<ul>
<li>Questions?</li>
</ul>
</ol>
</section>
<section>
<h3>Controllers & Views</h3>
<p class="textsmall">
Action View and Action Controller get requests and respond with HTML.
</p>
<p class="textsmall">
In Rails, web requests are handled by Action Pack, which splits the work into a controller part (performing the logic) and a view part (rendering a template).
</p>
<p class="textsmall">
Action Controller is concerned with communicating with the database and performing CRUD actions where necessary. Action View is then responsible for compiling the HTML response.
</p>
</section>
<section>
<h3>Simple HTTP Request</h3>
<img src="images/simple_rest_diagram.png" title="https://windyroad.com.au/static/images/image01.png" alt="simple HTTP diagram" />
</section>
<section>
<h3>HTTP Model-View-Contoller Request</h3>
<img src="images/http_mvc_request.png" title="https://msdn.microsoft.com/en-us/magazine/dd942833.aspx" alt="simple REST MVC diagram" />
</section>
<section>
<h3>Rails Request</h3>
<img src="images/rails_rest_request_diagram.png" title="http://paulhan221.tumblr.com/post/114731592051/rails-http-requests-for-mvc" alt="Rails request diagram" />
</section>
<section>
<h3>Detailed Rails Request</h3>
<img src="images/detailed_rails_request_diagram.png" title="https://github.com/sergey-alekseev/bsu-on-rails/wiki/Week-2-%C2%B7-MVC-architecture,-components-of-Rails" alt="Detailed Rails request diagram" />
</section>
<!-- Controllers -->
<section>
<h3>What is a controller?</h3>
<p>After the routes.rb has determined which controller to use for a request, your controller is responsible for making sense of the request and producing the appropriate output (action and view).</p>
<p><a href="http://guides.rubyonrails.org/action_controller_overview.html">More info...</a></p>
<pre>
<code>
class ArtistsController < ApplicationController
# route get 'songs#index' would direct here
def index
@artists = Artist.all
end
# route 'songs#show' would direct here
def show
@artist = Artist.find(params[:id])
@songs = @artist.songs
end
end
</code>
</pre>
</section>
<section>
<h3>BestSong Controllers</h3>
<br>
<table>
<tr>
<th style="border-bottom: 2px solid skyblue;">Controller</th>
<th colspan="3" style="border-bottom: 2px solid skyblue;">Actions</th>
</tr>
<tr>
<td>Artists</td>
<td>Index</td>
<td>Show</td>
</tr>
<tr>
<td>Songs</td>
<td>New</td>
<td>Create</td>
<td>Show</td>
</tr>
<tr>
<td>Ratings</td>
<td>New</td>
<td>Create</td>
</tr>
</table>
</section>
<section>
<h3>Building Controllers</h3>
<p>Let's work together to build the Artists, Songs, and Ratings controllers. Start with running the generate commands in the terminal: </p>
<pre><code>
$ rails generate controller Artists
$ rails generate controller Songs
$ rails generate controller Ratings
</code></pre>
</section>
<!-- Instructor leads class in building Artists, Songs, & Ratings controllers, with the actions listed in the previous section. Leave Ratings#new for the section below. -->
<section>
<h3>Let's Develop It!</h3>
<p>Build your own Song#new controller method. It will need to create a new Song and assign it to an instance variable, then find the artist by params, and assign them to instance variables. </p>
</section>
<section>
<h3>Let's Develop It!</h3>
<pre><code class="ruby">
# in app/controllers/ratings_controller.rb
def new
@song = Song.new
@artist = Artist.find(params[:artist_id])
end
</code></pre>
</section>
<!-- Routing -->
<section>
<h3>Routing</h3>
<p>The Rails router recognizes URLs and dispatches them to a controller's action. It can also generate paths and URLs, avoiding the need to hardcode strings in your views.</p>
<p>Since ratings belong to songs, and songs belong to artists, we need nested routes.</p>
<p><a href="http://guides.rubyonrails.org/routing.html">More info...</a></p>
<pre>
<code class="ruby">
# view all routes http://<app-name-here>/rails/info/routes
# in app/config/routes.rb
resources :artists do
resources :songs
end
</code>
</pre>
</section>
<section>
<h3>Routing View Page</h3>
<p>
http://<app-name-here>/rails/info/routes
</p>
<img src="images/rails_routes_view_page.png" alt="rails routes view" />
</section>
<!-- Views -->
<section>
<h3>What is a View</h3>
<p>Action View templates are written using embedded Ruby in tags mingled with HTML. To avoid cluttering the templates with boilerplate code, a number of helper classes provide common behavior for forms, dates, and strings. It's also easy to add new helpers to your application as it evolves.</p>
<ul>
<li>Layouts</li>
<li>Templates</li>
<li>Partials</li>
</ul>
<p><a href="http://guides.rubyonrails.org/layouts_and_rendering.html">More info...</a></p>
</section>
<section>
<h3>BestSong Views</h3>
<ul>
<li style="border-bottom: 2px solid skyblue;">Model/View</li>
<li>Layouts/Application</li>
<li>Artist/Index (root)</li>
<li>Artist/Show</li>
<li>Song/Show</li>
<li>Song/New</li>
<li>Song/_form</li>
<li>Rating/New</li>
<li>Rating/_form</li>
</ul>
</section>
<section>
<h3>Building Views</h3>
<p>Let's work together to build the Artists, Songs, and Ratings views.</p>
</section>
<!-- Instructor leads class in building the views listed in the section above. Time may not permit you to get through all of them. -->
<section>
<h3>Let's Develop It!</h3>
<p>Build your own Song/Show view</p>
</section>
<section>
<h3>Let's Develop It!</h3>
<pre><code class="html">
<h1><%= @song.title %></h1>
<p>Best played at <%= @song.optimal_volume %>. Rated as <%= @song.average_rating %> by people who would know.</p>
</code></pre>
</section>
<section>
<h3>Where Does CSS Go?</h3>
<p>app/assets/stylesheets</p>
<!-- brief discussion of assets directory if time permits and class is interested-->
</section>
<section>
<h3>Summary</h3>
<p>Today, we built the controllers and views for our application, including forms to create new songs and ratings, as well as all the necessary routing.</p>
<p>App code available <a href="https://github.com/cherimarie/bestsong">on Github</a>.</p>
</section>
<section>
<h3>Questions</h3>
<p>?</p>
</section>
<section>
<h3>Homework</h3>
<p>Ensure that you have an account set up on Heroku.com.</p>
<p>Read the documentation for the <a href="https://github.com/plataformatec/devise">Devise gem</a>. We'll be using it next week.</p>
</section>
</div>
<footer>
<div class="copyright">
Intro to Rails
<a rel="license" href="http://creativecommons.org/licenses/by-nc/3.0/deed.en_US"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-nc/3.0/80x15.png" /></a>
</div>
</footer>
</div>
<script src="reveal.js/lib/js/head.min.js"></script>
<script src="reveal.js/js/reveal.min.js"></script>
<script>
// Full list of configuration options available here:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
progress: true,
history: true,
theme: Reveal.getQueryHash().theme, // available themes are in /css/theme
transition: Reveal.getQueryHash().transition || 'default', // default/cube/page/concave/zoom/linear/none
// Optional libraries used to extend on reveal.js
dependencies: [
{ src: 'reveal.js/lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'reveal.js/plugin/markdown/showdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'reveal.js/plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'reveal.js/plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: 'reveal.js/plugin/zoom-js/zoom.js', async: true, condition: function() { return !!document.body.classList; } },
{ src: 'reveal.js/plugin/notes/notes.js', async: true, condition: function() { return !!document.body.classList; } }
]
});
</script>
</body>
</html>