Sha256: 89137e1d8d92a7ae5acf0d7a2a25a20bf71c9df38c0f06ddd68f6316081fd072

Contents?: true

Size: 1.24 KB

Versions: 10

Compression:

Stored size: 1.24 KB

Contents

# Blocks + fields = Magic

## Installation
Run the following generators to generate the migration files.
```
rails generate headmin:blocks
rails generate headmin:fields
rails db:migrate
```

## Getting Started
### Setup model

Setup a block model by including `Headmin::Fieldable`

```ruby
class Block < ApplicationRecord
  include Headmin::Block
  include Headmin::Fieldable
end
```

### Setup forms

```erb
# app/views/admin/blocks/_contact.html.erb
<%= form.hidden_field :name, value: :contact %>

<!-- Title -->
<%= render 'headmin/forms/fields/text', form: form, name: :title do |field, attribute, label| %>
  <%= render 'headmin/forms/text', form: field, attribute: attribute, label: label %>
<% end %>

<!-- People list -->
<%= render 'headmin/forms/fields/list', form: form, name: :people do |item| %>
  <%= render 'headmin/forms/fields/text', form: item, name: :name do |field, attribute, label| %>
    <%= render 'headmin/forms/text', form: field, attribute: attribute, label: label %>
  <% end %>
<% end %>
```

### Usage in website

```erb
# app/views/website/blocks/_contact.html.erb
<% fields = block.fields_hash %>

<h1><%= fields["title"] %></h1>
<ul>
  <% fields["people"].each do |person| %>
    <li><%= person["name"] %></h2></li>
  <% end %>
</ul>
```

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
headmin-0.2.9 docs/blocks-and-fields.md
headmin-0.3.4 docs/blocks-and-fields.md
headmin-0.3.3 docs/blocks-and-fields.md
headmin-0.3.2 docs/blocks-and-fields.md
headmin-0.3.1 docs/blocks-and-fields.md
headmin-0.2.8 docs/blocks-and-fields.md
headmin-0.2.7 docs/blocks-and-fields.md
headmin-0.2.6 docs/blocks-and-fields.md
headmin-0.2.5 docs/blocks-and-fields.md
headmin-0.2.4 docs/blocks-and-fields.md