[FAIL] Don't fix the same problem twice
And then it all made sense. The app uses band slugs (like "led-zeppelin") for ids, so the band_id was a string. In ruby, 'string'.to_i is 0, which is why all songs had a band_id of 0, and they didn't show up for any of the bands.
One of the Rock & Roll with Ember book's readers pointed out that songs are not persisted between reloads of the app.
I was pretty quick to find that the requests are correctly sent to the Rails back-end but that upon saving, the band_id attribute of the song is set to zero, severing the song's relationship to its band. It made sense then that it didn't show up.
I recently had to do two migrations. I "migrated" to a new laptop, and I also had to migrate the Rails 4 back-end to a Rails 6 one. I thought something was lost in the process, and I quickly found something (a belongs_to
definition) that was missing and could have caused the problem.
And yet, it still didn't work. I tried several things, then upgrading and downgrading the library responsible for JSON:API support, but nothing worked.
Then I recalled I still had an earlier version of the Rails app on my old laptop, so I checked for the missing piece and finally found it:
And then it all made sense. The app uses band slugs (like "led-zeppelin") for ids, so the band_id
was a string. In ruby, 'string'.to_i
is 0
, which is why all songs had a band_id of 0
, and they didn't show up for any of the bands.
A lot of problems seem easy to fix at first, only to doggedly resist fixing attempts. If you'd solved it before, it's better to look up the solution. What a great insight!