Draper - Decorators/View-Models for Rails Applications
Usage
class ArticleDecorator < Draper::Decorator
end
Generators
rails generate resource Article
rails generate decorator Article
Decorating
@article = Article.first.decorate
@widget = ProductDecorator.new(Widget.first)
@widget = ProductDecorator.decorate(Widget.first)
Decoration Collection
@articles = ArticleDecorator.decorate_collection(Article.all)
@articles = Article.popular.decorate
with Kaminari
class PaginatingDecorator < Draper::CollectionDecorator
delegate :current_page, :total_pages, :limit_value
end
References