Updating Song Ratings
You’ll learn to update the song's rating on the backend in this lesson.
Adding an action handler
The current action that handles clicking a star is dead-simple: it just updates the song’s rating using the set template helper. We’ll need to make it more complicated because it needs to update the song’s rating on the backend, too. This means we’ll have to write an action handler function and make the following changes in the code:
As this is a PATCH request, we only need to send the changes: the new rating.
This new updateRating function needs to be called from the template, so let’s make the modification there by removing the @onUpdate={{set song "rating"}} line and adding @onUpdate={{fn this.updateRating song}}:
Access this course and 1600+ top-rated courses and projects.