Behave as ActiveRecord. Why do we want objects to be AR lookalikes?

Pasha Kalashnikov
1 min readApr 8, 2024

You may love ActiveRecord, or you may hate ActiveRecord, but please be honest: it allows us to make our code amazing. And it’s indispensable in Rails now.

In addition to the constantly evolving ORM system, ActiveRecord is gaining many features that are well integrated into Rails. Therefore, we decided that Tramway Decorator and Tramway Form should contain some of those features. Cause we want to write amazing code still with Tramway!

For now, decorated and form becomes “imposter” in these cases:

  1. Arguments in Rails routes helpers
@user = tramway_decorate User.first

redirect user_path @user

2. Serializable objects

@user = tramway_decorate User.first

render json: @user, serializer: UserSerializer

3. Actionable objects (it does not work by default, you must use behave_as_ar method inside the decorator or form)

@user = tramway_form User.first

@user.update params

# OR

@user.destroy

You can find details here.

What do you think about this “imposter” stuff? :)

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

Write a response