Skip to content

Commit 9e4d645

Browse files
shouichiEdouard-chin
authored andcommitted
Clarify Active Storage setup for importmap-rails
1 parent 59a64cd commit 9e4d645

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

activestorage/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,10 @@ Active Storage, with its included JavaScript library, supports uploading directl
173173
```erb
174174
<%= form.file_field :attachments, multiple: true, direct_upload: true %>
175175
```
176-
3. That's it! Uploads begin upon form submission.
176+
177+
3. Configure CORS on third-party storage services to allow direct upload requests.
178+
179+
4. That's it! Uploads begin upon form submission.
177180
178181
### Direct upload JavaScript events
179182

guides/source/active_storage_overview.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,27 @@ directly from the client to the cloud.
10491049

10501050
### Usage
10511051

1052-
1. Include `activestorage.js` in your application's JavaScript bundle.
1052+
1. Include the Active Storage JavaScript in your application's JavaScript bundle or reference it directly.
1053+
1054+
Requiring directly without bundling through the asset pipeline in the application HTML with autostart:
1055+
1056+
```erb
1057+
<%= javascript_include_tag "activestorage" %>
1058+
```
1059+
1060+
Requiring via importmap-rails without bundling through the asset pipeline in the application HTML without autostart as ESM:
1061+
1062+
```ruby
1063+
# config/importmap.rb
1064+
pin "@rails/activestorage", to: "activestorage.esm.js"
1065+
```
1066+
1067+
```html
1068+
<script type="module-shim">
1069+
import * as ActiveStorage from "@rails/activestorage"
1070+
ActiveStorage.start()
1071+
</script>
1072+
```
10531073
10541074
Using the asset pipeline:
10551075
@@ -1064,7 +1084,7 @@ directly from the client to the cloud.
10641084
ActiveStorage.start()
10651085
```
10661086
1067-
2. Add `direct_upload: true` to your [file field](form_helpers.html#uploading-files):
1087+
2. Annotate file inputs with the direct upload URL using Rails' [file field helper](form_helpers.html#uploading-files).
10681088
10691089
```erb
10701090
<%= form.file_field :attachments, multiple: true, direct_upload: true %>

0 commit comments

Comments
 (0)