- Use AMS to render JSON.
- Use AMS to render JSON associations.
We're going to continue updating our products/orders system to use ActiveModel::Serializer for JSON serialization. The solution to the previous lab is provided.
Don't forget to run rake db:seed
for some starter data and lots of
Latin practice!
- Create an ActiveModel::Serializer for
Product
and update theproducts_controller
to use the new serializer in place of the existingto_json
code. - Update the product show page to handle the new JSON.
- On the products
index
page, update theMore Info
button so that it uses the/products/id.json
route to get both description and inventory.
- Note: The serializer will return a different value for
inventory
than the previous API, so you'll have to handle that.
- Update the
ProductSerializer
to include the orders for the product. - Update the
More Info
button on the productsindex
page to show a list of orders withid
andcreated_at
in addition to the description and inventory. - Update the
OrderSerializer
to include the product names of all products on that order, and display them with the order information after clickingMore Info
on/products
.
- Note: Look out for the circular reference problem! Remember that you can create new serializers and render them explicitly.
- Get rid of the unused
/products/id/description
and/products/id/inventory
routes. - Make sure tests pass!