Sha256: b98cb44f4bc3c2c92b2174dcb2d5183b69941d529569139640d66e0d622245f1

Contents?: true

Size: 1.96 KB

Versions: 38

Compression:

Stored size: 1.96 KB

Contents

# Examples and setup for the `file_field` Field Partial

## Active Storage

`file_field` is designed to be used with [Active Storage](https://edgeguides.rubyonrails.org/active_storage_overview.html). You will need to confgure Active Storage for your application before using this field partial. You can find instructions for doing so in the [Rails Guides](https://edgeguides.rubyonrails.org/active_storage_overview.html#setup).

In addition, Bullet Train has integrated the direct-uploads feature of Active Storage. For this to work, you need to have CORS configured for your storage endpoint. You can find instructions for doing so in the [Rails Guides](https://edgeguides.rubyonrails.org/active_storage_overview.html#cross-origin-resource-sharing-cors-configuration).

## Example

The following steps illustrate how to add a `document` file attachment to a `Post` model.

Add the following to `app/models/post.rb`:

```ruby
has_one_attached :document
```

Note, no database migration is required as ActiveStorage uses its own tables to store the attachments.

Run the following command to generate the scaffolding for the `document` field on the `Post` model:

```bash
rails generate super_scaffold:field Post document:file_field
```

## Multiple Attachment Example

The following steps illustrate how to add multiple `document` file attachments to a `Post` model.

Add the following to `app/models/post.rb`:

```ruby
has_many_attached :documents
```

Note, no database migration is required as ActiveStorage uses its own tables to store the attachments.

Run the following command to generate the scaffolding for the `documents` field on the `Post` model:

```bash
rails generate super_scaffold:field Post documents:file_field{multiple}
```

## Generating a Model & Super Scaffold Example

If you're starting fresh, and don't have an existing model you can do something like this:

```
rails generate super_scaffold Project Team name:text_field specification:file_field documents:file_field{multiple}
```

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
bullet_train-1.8.0 docs/field-partials/file-field.md
bullet_train-1.7.23 docs/field-partials/file-field.md
bullet_train-1.7.22 docs/field-partials/file-field.md
bullet_train-1.7.21 docs/field-partials/file-field.md
bullet_train-1.7.20 docs/field-partials/file-field.md
bullet_train-1.7.19 docs/field-partials/file-field.md
bullet_train-1.7.18 docs/field-partials/file-field.md
bullet_train-1.7.17 docs/field-partials/file-field.md
bullet_train-1.7.16 docs/field-partials/file-field.md
bullet_train-1.7.15 docs/field-partials/file-field.md
bullet_train-1.7.14 docs/field-partials/file-field.md
bullet_train-1.7.13 docs/field-partials/file-field.md
bullet_train-1.7.12 docs/field-partials/file-field.md
bullet_train-1.7.11 docs/field-partials/file-field.md
bullet_train-1.7.10 docs/field-partials/file-field.md
bullet_train-1.7.9 docs/field-partials/file-field.md
bullet_train-1.7.3 docs/field-partials/file-field.md
bullet_train-1.7.2 docs/field-partials/file-field.md
bullet_train-1.7.1 docs/field-partials/file-field.md
bullet_train-1.7.0 docs/field-partials/file-field.md