Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialize generator already adds attributes #62

Open
notapatch opened this issue Jan 24, 2021 · 0 comments
Open

Serialize generator already adds attributes #62

notapatch opened this issue Jan 24, 2021 · 0 comments

Comments

@notapatch
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant