An ORM-agnostic decorator pattern library for Rails that automatically enhances models with view-specific logic.
ActiveDecorator is a Ruby gem that implements the decorator pattern for Rails applications, allowing developers to add view-specific methods to models without modifying the models directly. It automatically decorates model objects when they are passed to views, enabling a clean separation of presentation logic from business logic. The gem is ORM-agnostic and works seamlessly with Rails helpers.
Rails developers who want to keep their models lean and avoid bloating them with presentation logic, especially those building maintainable applications with complex view requirements.
Developers choose ActiveDecorator because it provides a Rubyish, object-oriented approach to view helpers that automatically decorates models, reducing boilerplate and keeping code organized. Its ORM-agnostic design and seamless integration with Rails view helpers make it a flexible and powerful alternative to traditional helper modules.
ORM agnostic truly Object-Oriented view helper for Rails 4, 5, 6, 7, and 8
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Decorator modules are automatically mixed into models when passed to views or in partials, reducing boilerplate code for common Rails patterns like rendering collections.
Decorators can directly call ActionView helper methods like link_to, allowing presentation logic to blend naturally with Rails view conventions without extra configuration.
Works with ActiveRecord, ActiveResource, and other ORMs, and supports a wide range of Ruby and Rails versions from legacy to edge, ensuring long-term compatibility.
Allows customization of decorator suffixes via an initializer, so teams can use conventions like 'Presenter' instead of 'Decorator' to match project standards.
Automatic decoration only works in the Rails view context; for use in APIs, jobs, or other contexts, developers must manually wrap code with ActiveDecorator::ViewContext.run_with, adding complexity.
The implicit mixing of decorators can make debugging harder, as it's not always clear when a model is decorated, leading to potential confusion in large codebases.
The README provides basic examples but lacks guidance on edge cases, performance optimization, or integration with modern Rails features like Hotwire or STI models.