Sha256: f3665c86cae0840566e83b03d82d667c67c8f06c93ce507c3ddafb810afe0c33

Contents?: true

Size: 1.23 KB

Versions: 2

Compression:

Stored size: 1.23 KB

Contents

# Blocks 

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

## Getting Started

### Setup model

```ruby
class Page < ApplicationRecord
  include Headmin::Blockable
end
```

### Setup forms

The view "headmin/forms/blocks" will render all the form views for the blocks in the database.
A hidden template form will be rendered for all types defined in `allow:`

```erb
# app/views/admin/pages/_form.html.erb
<%= render 'headmin/form', model: [:admin, @page] do |form| %>
  <%= render "headmin/forms/blocks", form: form %>
<% end %>
```

For each type of block you want to include, create a template in `views/admin/blocks`.
Make sure to include a hidden field to store the name of the block.

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

### Usage in frontend

```erb
# app/views/website/pages/show.html.erb
<%= render 'headmin/blocks', blockable: @page %>
```

This will render all the blocks associated with the blockable model (e.g. Page).

For each block in the admin, you'll need to create a corresponding template in your frontend.

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
headmin-0.2.5 docs/blocks.md
headmin-0.2.4 docs/blocks.md