-
Notifications
You must be signed in to change notification settings - Fork 8
/
class3.html
268 lines (220 loc) · 10.3 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
<!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 -->
<!-- light editor<link rel="stylesheet" href="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]-->
</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">
<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>
<p>Questions?</p>
</section>
<section>
<h3>Controllers & Views</h3>
<p>Action View and Action Controller are the two major components of Action Pack. 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). Typically, Action Controller will be concerned with communicating with the database and performing CRUD actions where necessary. Action View is then responsible for compiling the response.</p>
</section>
<!-- Controllers -->
<section>
<h3>What is a controller?</h3>
<p>After routing 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" alt="rails guides controllers">More info...</a></p>
</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 Rating#new controller method. It will need to create a new Rating and assign it to an instance variable, then find the song and 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
@rating = Rating.new
@song = Song.find(params[:song_id])
@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" alt="rails guides routing">More info...</a></p>
</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" alt="rails guides views">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" alt="github repo">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" alt="Devise gem">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>