Sha256: 0c922bb2cb3b251fa3340b2142083d6584a3cd99168c9d896ec85b444041ccf6

Contents?: true

Size: 964 Bytes

Versions: 23

Compression:

Stored size: 964 Bytes

Contents

# Getting Started

## Installation

To install Panko, all you need is to add it to your Gemfile:

```ruby
gem "panko_serializer"
```

Then, install it on the command line:

```
> bundle install
```


## Creating your first serializer

Let's create serializer and use it inside Rails controller.

```ruby
class PostSerializer < Panko::Serializer
  attributes :title
end

class UserSerializer < Panko::Serializer
  attributes :id, :name, :age

  has_many :posts, serializer: PostSerializer
end
```

As you can see, defining serializers is simple and resembles ActiveModelSerializers 0.9,
To utilize the `UserSerializer` inside a Rails controller and serialize some users, all we need to do is:

```ruby
class UsersController < ApplicationController
 def index
   users = User.includes(:posts).all
   render json: Panko::ArraySerializer.new(users, each_serializer: UserSerializer).to_json
 end
end
```

And voila, we have endpoint which serialize users using Panko!

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
panko_serializer-0.7.0 docs/getting-started.md
panko_serializer-0.6.0 docs/getting-started.md
panko_serializer-0.5.10 docs/getting-started.md
panko_serializer-0.5.9 docs/getting-started.md
panko_serializer-0.5.8 docs/getting-started.md
panko_serializer-0.5.7 docs/getting-started.md
panko_serializer-0.5.6 docs/getting-started.md
panko_serializer-0.5.5 docs/getting-started.md
panko_serializer-0.5.4 docs/getting-started.md
panko_serializer-0.5.3 docs/getting-started.md
panko_serializer-0.5.2 docs/getting-started.md
panko_serializer-0.5.1 docs/getting-started.md
panko_serializer-0.5.0 docs/getting-started.md
panko_serializer-0.4.4 docs/getting-started.md
panko_serializer-0.4.3 docs/getting-started.md
panko_serializer-0.4.2 docs/getting-started.md
panko_serializer-0.4.0 docs/getting-started.md
panko_serializer-0.3.9 docs/getting-started.md
panko_serializer-0.3.7 docs/getting-started.md
panko_serializer-0.3.6 docs/getting-started.md