Skip to content

Serialize generator already adds attributes #62

@notapatch

Description

@notapatch

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions