Sha256: 2ef903f84b79ad6b1fe131b8dea8164cd2d0b8234f27a6cf34b135da716a9465

Contents?: true

Size: 928 Bytes

Versions: 5

Compression:

Stored size: 928 Bytes

Contents

# Decorators

Active Admin allows you to use the decorator pattern to provide view-specific
versions of a resource. [Draper](https://github.com/drapergem/draper) is
recommended but not required.

## Example usage

```ruby
# app/models/post.rb
class Post < ActiveRecord::Base
  # has title, content, and image_url
end

# app/decorators/post_decorator.rb
class PostDecorator < ApplicationDecorator
  delegate_all

  def image
    h.image_tag model.image_url
  end
end

# app/admin/post.rb
ActiveAdmin.register Post do
  decorate_with PostDecorator

  index do
    column :title
    column :image
    actions
  end
end
```

## Forms

By default, ActiveAdmin does *not* decorate the resource used to render forms.
If you need ActiveAdmin to decorate the forms, you can pass `decorate: true` to the
form block.

```ruby
ActiveAdmin.register Post do
  decorate_with PostDecorator

  form decorate: true do |f|
    # ...
  end
end
```

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
active_administration-0.0.3 docs/11-decorators.md
activeadministration-0.0.2 docs/11-decorators.md
active_administration-0.0.2 docs/11-decorators.md
activeadministration-0.0.1 docs/11-decorators.md
active_administration-0.0.1 docs/11-decorators.md