rockandrollwithemberjs / rarwe-issues

Errata and updates for the Rock and Roll with Ember.js book
https://rockandrollwithemberjs.com
43 stars 4 forks source link

Chapter 6 StarRating on "click" not working #497

Closed cedriclinares closed 3 years ago

cedriclinares commented 3 years ago

I followed the instructions in the rarwe Octane book. Everything was working correctly until I tried to implement editing the song rating and I don't know what is wrong.

Here is star-rating.hbs: {{#each this.stars as |star|}} <button type="button" {{on "click" (fn @onUpdate star.rating)}}> <FaIcon @icon="star" @prefix={{if star.full "fas" "far"}} /> </button> {{/each}}

songs.hbs: {{#if @model.length}} <ul> {{#each @model as |song|}} <li class="mb-2"> {{song.title}} <span class="float-right"> <StarRating @rating={{song.rating}} @onUpdate={{set song.rating}} /> </span> </li> {{/each}} </ul> {{else}} <p class="text-center"> The band has no songs yet. </p> {{/if}}

The console gives me an error

Uncaught (in promise) Error: Assertion Failed: you must pass a path to {{set}}. You can pass a path statically, as in {{set this.foo}}, or with the path argument dynamically, as in {{set this path="foo"}}

When I click on a star nothing happens. I don't think the on click is being called because I tried to log a string and it would not print to the console. Please help!

balinterdi commented 3 years ago

Hey Cedric,

Is it possible that you’re using version 2.0.0 of ember-set-helper? https://github.com/pzuraq/ember-set-helper/releases/tag/v2.0.0

In the book we use version 1.1.0 and I just double-checked that the code works fine with it.

If you do have 2.0.0, that explains the difference and I’ll have to update the examples that have {{set}} in them for the next release.

Could you confirm that?

cedriclinares commented 3 years ago

Yes I have version 2.0.0. I'll switch over to 1.1.0!

fabmiz commented 3 years ago

I had the same issue with ember-set-helper v2.0.0. Using set helper this way worked for me.

<StarRating
    @rating={{song.rating}}
    @onUpdate={{set song 'rating'}}
/>
balinterdi commented 3 years ago

@cedriclinares @fabmiz Thank you, I'll update the book for v2.0.0 for the next release.