Sha256: 499be60fe88d7fc2fa40f9a2fdc466f7c4b85f948fe7631416772232c25e9075
Contents?: true
Size: 1.27 KB
Versions: 19
Compression:
Stored size: 1.27 KB
Contents
# Inline Decorators In most use cases it is recommended to use [View Decorators](view-decorators.html) to render custom data to provide reusable and composable view fragments without polluting component definitions with custom logic. However, if you need a simple one-off data transformation when using a [Table](../components/tables.html), you can specify a `Proc` within the table `fields` definition by using the secondary form of passing an `Array` of `[Symbol, Hash]` instead of just a `Symbol` for any given field. The `Proc` will receive the current record (i.e. the object for the current row of a `collection` with a [Collection Table](../components/tables/collection-table.html) or the `item` with an [Item Table](components/tables/item-table.html)). ```rspec:html collection = [ User.new(name: 'John Smith', email: 'john@example.com'), User.new(name: 'Sally Anderson', email: 'sally@example.org') ] subject do active_element.component.table collection: collection, fields: [ :email, [:name, { mapper: ->(record) { record.name.upcase } }] ] end it { is_expected.to include 'JOHN SMITH' } it { is_expected.to include 'SALLY ANDERSON' } ```
Version data entries
19 entries across 19 versions & 1 rubygems