api_on_rails icon indicating copy to clipboard operation
api_on_rails copied to clipboard

Serialize generator already adds attributes

Open notapatch opened this issue 4 years ago • 0 comments

In Chapter 6 - section Serialize Products. We use a generator like so:

rails generate serializer Product title price published

This automatically adds the attributes. However, in the text you are encouraged to add the, already created, attributes. As follows:

Suggested changes

$ rails generate serializer Product title price published
      create  app/serializers/product_serializer.rb

~~Now let’s add attributes to serialize the product:~~ Now check the generated product serializer:

Listing 75. app/serializers/product_serializer.rb
class ProductSerializer
  include JSONAPI::Serializer
  attributes :title, :price, :published
end

~~There you go. It’s no more complicated than that.~~ Everything looks right. Let’s change our controller a little bit.

notapatch avatar Jan 24 '21 11:01 notapatch