Sha256: 9d055ef05f5df32b031ed57301ea60d2de0eeefa755a4377e2184a57e3cd1297

Contents?: true

Size: 1.21 KB

Versions: 25

Compression:

Stored size: 1.21 KB

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.

To use decorator support without Draper, your decorator must support a variety
of collection methods to support pagination, filtering, etc. See
[this github issue discussion](https://github.com/activeadmin/activeadmin/issues/3600)
and [this gem](https://github.com/kiote/activeadmin-poro-decorator) for more details.

## 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 < Draper::Decorator
  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

25 entries across 25 versions & 4 rubygems

Version Path
activeadmin_addons-1.1.2 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-a5a53c3f2b8f/docs/11-decorators.md
activeadmin_addons-1.1.1 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/docs/11-decorators.md
yousty-activeadmin-1.0.17.pre docs/11-decorators.md
yousty-activeadmin-1.0.16.pre docs/11-decorators.md
activeadmin_addons-1.1.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/docs/11-decorators.md
activeadmin_addons-1.0.1 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/docs/11-decorators.md
activeadmin_addons-1.0.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/docs/11-decorators.md
yousty-activeadmin-1.0.15.pre docs/11-decorators.md
activeadmin-orac-1.0.0.pre4 docs/11-decorators.md
activeadmin-orac-1.0.0 docs/11-decorators.md
activeadmin-orac-1.0.0.pre.orac docs/11-decorators.md
yousty-activeadmin-1.0.14.pre docs/11-decorators.md
yousty-activeadmin-1.0.13.pre docs/11-decorators.md
yousty-activeadmin-1.0.12.pre docs/11-decorators.md
yousty-activeadmin-1.0.11.pre docs/11-decorators.md
yousty-activeadmin-1.0.10.pre docs/11-decorators.md
yousty-activeadmin-1.0.9.pre docs/11-decorators.md
yousty-activeadmin-1.0.8.pre docs/11-decorators.md
activeadmin-1.0.0.pre4 docs/11-decorators.md
activeadmin-1.0.0.pre3 docs/11-decorators.md