I’m running into a common pattern over and over again with Ember Data + Rails API + ActiveModel Serializers and am wondering what others are doing, if there’s a best practice, and feedback on my current approach.
Let’s say I have a Product model. When the user is at /#/products, the user should see a list of products with only the basic information: name, picture, and price. When the user goes to a product page, such as /#/products/1, he should see all the extended information about the product: reviews, variations, similar items, etc. Likewise, it seems to make sense to structure the API similarly: /products returns the basic information about many products, and /products/1 returns the extended information about a single product.
On the Rails side, I have two different Product serializers: one for the basic version and one for the detailed version, and the controller determines which serializer to use. Ember Data seems pretty happy with this approach, with one exception: when the user visits the /#/products page and then visits /#/products/1, the basic model is already loaded, so it will not necessarily know to reload the model to get the extended information. My solution for that is to define a DS.attr called “_received” that the detailed serializer will return as true. When the ProductIndexRoute retrieves the model, it calls reload() if _received is false.
The approach works fairly well, but it seems like a non-standard approach to a common problem. Is there a more standard approach? Anyone solving the problem differently?