Skip to content

Commit ee59d6d

Browse files
committed
Ember tut: Tweak diffs and plurals in commands to match reality and conventions
1 parent 5613022 commit ee59d6d

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

TUTORIALS.md

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -260,28 +260,35 @@ EmberJS applications roughly follow the Web-MVC pattern. The applications have
260260

261261
```sh
262262
edi ember generate model book title:string isbn:string
263-
edi ember generate route book
264-
edi ember generate controller book
263+
edi ember generate route books
264+
edi ember generate controller books
265265
```
266266

267267
The terminal output shows the created and updated files. (note: generating new files can make watched files fail in Docker, just kill and restart eds should that happen.)
268268

269-
We will fetch all books and render them in our template. In routes/book.js:
269+
We will fetch all books and render them in our template. In routes/books.js:
270270

271271
```diff
272+
= import Route from '@ember/routing/route';
273+
+ import { inject as service } from '@ember/service';
274+
=
272275
= export default class BooksRoute extends Route {
276+
+ @service store;
277+
+
273278
+ model(){
274279
+ return this.store.findAll('book');
275280
+ }
276281
= }
277282
```
278283

279-
We’ll display the found records in our template so we’re able to see the created records later on. Add the following to templates/book.hbs
284+
We’ll display the found records in our template so we’re able to see the created records later on. Add the following to templates/books.hbs
280285

281286
```diff
282287
+ <ul>
283288
+ {{#each @model as |book|}}
284-
+ <li>{{book.title}} <small>{{book.isbn}}</small></li>
289+
+ <li>
290+
+ {{book.title}} <small>{{book.isbn}}</small>
291+
+ </li>
285292
+ {{/each}}
286293
+ </ul>
287294
```
@@ -311,15 +318,16 @@ In the app/templates/book.hbs template, we’ll add our create fields and button
311318
+ </form>
312319
```
313320

314-
We’ll add this action in the controller and make it create the new book. In app/controllers/book.hbs add the following:
321+
We’ll add this action in the controller and make it create the new book. In app/controllers/books.js add the following:
315322

316323
```diff
317324
= import Controller from '@ember/controller';
318325
+ import { action } from '@ember/object';
319326
+ import { tracked } from '@glimmer/tracking';
320327
+ import { inject as service } from '@ember/service';
321328
=
322-
= export default class BooksController extends Controller {
329+
- export default class BooksController extends Controller {}
330+
+ export default class BooksController extends Controller {
323331
+ @tracked newTitle = '';
324332
+ @tracked newIsbn = '';
325333
+
@@ -338,7 +346,7 @@ We’ll add this action in the controller and make it create the new book. In a
338346
+ this.newTitle = '';
339347
+ this.newIsbn = '';
340348
+ }
341-
= });
349+
+ });
342350
```
343351

344352
#### Removing books
@@ -348,28 +356,24 @@ Removing books follows a similar path to creating new books. We add a delete bu
348356
In app/templates/book.hbs we alter:
349357

350358
```diff
351-
= <ul>
352-
= {{#each @model as |book|}}
353-
+ <li>
354-
+ {{book.title}}<small>{{book.isbn}}</small>
359+
= <li>
360+
= {{book.title}}<small>{{book.isbn}}</small>
355361
+ <button {{on "click" (fn this.removeBook book)}}>Remove</button>
356-
+ </li>
357-
= {{/each}}
358-
= </ul>
362+
= </li>
359363
```
360364

361-
In app/controllers/book.hbs we alter:
365+
In app/controllers/books.js we alter:
362366

363367
```diff
364368
= this.newTitle = '';
365369
= this.newIsbn = '';
366370
= }
367371
+
368372
+ @action
369-
+ removeBook( book, event ) {
373+
+ removeBook(book, event) {
370374
+ event.preventDefault();
371375
+ book.destroyRecord();
372-
= }
376+
+ }
373377
= }
374378
```
375379

0 commit comments

Comments
 (0)