@rails/activestorage 6.1.4 → 7.0.0-rc2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -11
- package/app/assets/javascripts/activestorage.esm.js +856 -0
- package/app/assets/javascripts/activestorage.js +270 -377
- package/package.json +8 -11
- package/src/blob_record.js +10 -3
- package/src/direct_upload.js +4 -2
- package/src/direct_upload_controller.js +9 -1
- package/src/ujs.js +1 -1
- package/CHANGELOG.md +0 -306
package/README.md
CHANGED
|
@@ -32,7 +32,7 @@ class User < ApplicationRecord
|
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
# Attach an avatar to the user.
|
|
35
|
-
user.avatar.attach(io: File.open("/path/to/face.jpg"), filename: "face.jpg", content_type: "image/
|
|
35
|
+
user.avatar.attach(io: File.open("/path/to/face.jpg"), filename: "face.jpg", content_type: "image/jpeg")
|
|
36
36
|
|
|
37
37
|
# Does the user have an avatar?
|
|
38
38
|
user.avatar.attached? # => true
|
|
@@ -88,8 +88,7 @@ class MessagesController < ApplicationController
|
|
|
88
88
|
end
|
|
89
89
|
|
|
90
90
|
def create
|
|
91
|
-
message = Message.create! params.require(:message).permit(:title, :content)
|
|
92
|
-
message.images.attach(params[:message][:images])
|
|
91
|
+
message = Message.create! params.require(:message).permit(:title, :content, images: [])
|
|
93
92
|
redirect_to message
|
|
94
93
|
end
|
|
95
94
|
|
|
@@ -124,27 +123,42 @@ When the application is configured to proxy files by default, use the `rails_sto
|
|
|
124
123
|
|
|
125
124
|
Optionally, files can be proxied instead. This means that your application servers will download file data from the storage service in response to requests. This can be useful for serving files from a CDN.
|
|
126
125
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
```erb
|
|
130
|
-
<%= image_tag rails_storage_proxy_path(@user.avatar) %>
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
Or configure Active Storage to use proxying by default:
|
|
126
|
+
You can configure Active Storage to use proxying by default:
|
|
134
127
|
|
|
135
128
|
```ruby
|
|
136
129
|
# config/initializers/active_storage.rb
|
|
137
130
|
Rails.application.config.active_storage.resolve_model_to_route = :rails_storage_proxy
|
|
138
131
|
```
|
|
139
132
|
|
|
133
|
+
Or if you want to explicitly proxy specific attachments there are URL helpers you can use in the form of `rails_storage_proxy_path` and `rails_storage_proxy_url`.
|
|
134
|
+
|
|
135
|
+
```erb
|
|
136
|
+
<%= image_tag rails_storage_proxy_path(@user.avatar) %>
|
|
137
|
+
```
|
|
138
|
+
|
|
140
139
|
## Direct uploads
|
|
141
140
|
|
|
142
141
|
Active Storage, with its included JavaScript library, supports uploading directly from the client to the cloud.
|
|
143
142
|
|
|
144
143
|
### Direct upload installation
|
|
145
144
|
|
|
146
|
-
1. Include
|
|
145
|
+
1. Include the Active Storage JavaScript in your application's JavaScript bundle or reference it directly.
|
|
147
146
|
|
|
147
|
+
Requiring directly without bundling through the asset pipeline in the application html with autostart:
|
|
148
|
+
```html
|
|
149
|
+
<%= javascript_include_tag "activestorage" %>
|
|
150
|
+
```
|
|
151
|
+
Requiring via importmap-rails without bundling through the asset pipeline in the application html without autostart as ESM:
|
|
152
|
+
```ruby
|
|
153
|
+
# config/importmap.rb
|
|
154
|
+
pin "@rails/activestorage", to: "activestorage.esm.js"
|
|
155
|
+
```
|
|
156
|
+
```html
|
|
157
|
+
<script type="module-shim">
|
|
158
|
+
import * as ActiveStorage from "@rails/activestorage"
|
|
159
|
+
ActiveStorage.start()
|
|
160
|
+
</script>
|
|
161
|
+
```
|
|
148
162
|
Using the asset pipeline:
|
|
149
163
|
```js
|
|
150
164
|
//= require activestorage
|