Decorating associations in Rails with Tramway

We already talked about decorators in Rails here [Delegating ActiveRecord methods to decorators in Rails].

Now we provide a new feature — decorating association via Tramway Decorator.

How it works

class User < ApplicationRecord
has_many :posts
end

class UserDecorator < Tramway::BaseDecorator
association :posts
end

class PostDecorator < Tramway::BaseDecorator
# stuff you need
end

user = tramway_decorate User.first
user.posts #=> returns collection of decorated object with PostDecorator

Well, it makes it simple to make a kinda “Decorating structure”. You always know that once you decorate one object it decorates all associations you set to be decorated.

Install the last version of Tramway Gem for this.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet