Rails 6 API Tutorial - Creating Multiple Records in Controllers p.13

preview_player
Показать описание
In this video series we will build a Rails API from scratch. Backend APIs are useful for serving data to frontend applications, mobile apps or other backend services.

This video covers:
0:00 - Introduction
0:32 - Benefits of using test driven development (TDD)
0:59 - Running the failing CREATE action spec
2:06 - Rewriting the params in separate book and author hashes
5:26 - Creating multiple records in the controller
6:41 - Merging author_id into the book params to associate the two records together
8:16 - Tidying up the book_params method
8:48 - Adding an assertion to check the Author record was created in the DB

Рекомендации по теме
Комментарии
Автор

Really helpful series. Only suggestion I have here is to use to avoid duplicate authors.

jds
Автор

Thanks man, this series helped me a lot ❤

ahmedmustafa
Автор

I learned a lot in this video! thank you <3

skalippanbalippan
Автор

This is great! How would you handle the strong_params if you wanted to accept an array of authors for a book?

darkpill
Автор

It would make a lot more sense to have book have accepts_nested_attributes_for :author, then you can just pass the whole params objected Book.create and the book and the author will be created at the same time. It would also rollback correctly if the author was saved, but the book failed validation, in your current implementation this scenario would leave an orphaned author record.

chris
Автор

author create should be its own endpoint

iapplethis