Sha256: 88ef85d8f0403b91892753ce55865595d315678b9946e6c2e9923fec07c54311

Contents?: true

Size: 1.28 KB

Versions: 2

Compression:

Stored size: 1.28 KB

Contents

# Tables

## Collection Table

The _Collection Table_ component provides a vertical table containing a collection of items item. Use with _Active Record_ model instances, an array of objects that extend `ActiveModel::Naming`, or simple hash-like objects.

Field types are automatically inferred from their respective database columns and rendered using an appropriate formatter.

```rspec:html
class User < ActiveRecord::Base
end

collection = [
  User.new(name: 'John', email: 'john@example.com'),
  User.new(name: 'Jane', email: 'jane@example.org')
]

html = active_element_component.table collection: collection, fields: [:name, :email]

it_documents html do
  expect(html).to include 'John'
end
```

## Item Table

The _Item Table_ component provides a horizontal table containing a single item and its attributes. It supports the same item types as [Collection Tables](##Collection Table).

```rspec:html
class User < ActiveRecord::Base
end

item = User.new(name: 'John', email: 'john@example.com', overview: 'Writes Ruby code for a living.')

html = active_element_component.table item: item, fields: [:name, :email, :password, :secret]

it_documents html do
  expect(html).to include 'John'
end
```

```rspec
foo = { foo: 'bar', baz: 'qux' }
it_documents foo do
  expect('hello').to eql 'hello'
end
```

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
active_element-0.0.3 rspec-documentation/pages/Components/Tables.md
active_element-0.0.2 rspec-documentation/pages/Components/Tables.md