rails_com 1.2.4 → 1.2.5
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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/Rakefile +4 -17
- data/app/assets/images/image-square.png +0 -0
- data/app/assets/javascripts/rails_com/application.js +43 -1
- data/{lib/assets/javascripts/input-attachment.js → app/assets/javascripts/rails_com/attachment.js} +24 -150
- data/app/assets/javascripts/rails_com/picture.js +17 -0
- data/app/controllers/{active_storage → active_storage_ext/admin}/attachments_controller.rb +2 -2
- data/app/controllers/active_storage_ext/admin/base_controller.rb +4 -0
- data/app/controllers/active_storage_ext/admin/blob_defaults_controller.rb +54 -0
- data/app/controllers/active_storage_ext/admin/blobs_controller.rb +48 -0
- data/app/controllers/active_storage_ext/audios_controller.rb +24 -0
- data/app/controllers/concerns/rails_common_api.rb +50 -0
- data/app/controllers/concerns/rails_common_xhr.rb +15 -0
- data/app/helpers/rails_com/active_helper.rb +21 -9
- data/app/helpers/rails_com/assets_helper.rb +57 -23
- data/app/helpers/rails_com/format_helper.rb +2 -2
- data/app/helpers/rails_com/time_helper.rb +2 -1
- data/app/models/active_storage/blob_default.rb +5 -0
- data/app/models/application_record.rb +3 -0
- data/app/models/{state_machine.rb → concerns/state_machine.rb} +0 -0
- data/app/views/{active_storage → active_storage_ext/admin}/attachments/destroy.js.erb +0 -0
- data/app/views/active_storage_ext/admin/blob_defaults/_form.html.erb +7 -0
- data/app/views/active_storage_ext/admin/blob_defaults/_search_form.html.erb +7 -0
- data/app/views/active_storage_ext/admin/blob_defaults/edit.html.erb +9 -0
- data/app/views/active_storage_ext/admin/blob_defaults/index.html.erb +48 -0
- data/app/views/active_storage_ext/admin/blob_defaults/new.html.erb +9 -0
- data/app/views/active_storage_ext/admin/blob_defaults/show.html.erb +10 -0
- data/app/views/active_storage_ext/admin/blobs/_search_form.html.erb +9 -0
- data/app/views/active_storage_ext/admin/blobs/destroy.js.erb +1 -0
- data/app/views/active_storage_ext/admin/blobs/index.html.erb +51 -0
- data/app/views/active_storage_ext/admin/blobs/new.html.erb +13 -0
- data/app/views/active_storage_ext/admin/blobs/show.html.erb +10 -0
- data/app/views/active_storage_ext/attachments/_default_image_item.html.erb +6 -0
- data/app/views/active_storage_ext/attachments/_image_item.html.erb +6 -0
- data/app/views/{active_storage → active_storage_ext}/attachments/_list.html.erb +1 -4
- data/app/views/{active_storage → active_storage_ext}/attachments/_list_edit.html.erb +1 -1
- data/app/views/{active_storage → active_storage_ext}/attachments/_list_form.html.erb +8 -8
- data/app/views/{active_storage → active_storage_ext}/attachments/_video_item.html.erb +0 -0
- data/app/views/active_storage_ext/audios/show.html.erb +5 -0
- data/config/locales/en.yml +2 -1
- data/config/locales/zh.yml +2 -1
- data/config/routes.rb +13 -6
- data/db/migrate/20181012025833_rails_com_init.rb +13 -0
- data/lib/mina/sidekiq.rb +3 -1
- data/lib/rails_com.rb +3 -1
- data/lib/rails_com/config.rb +2 -1
- data/lib/rails_com/core_ext/array.rb +2 -2
- data/lib/rails_com/core_ext/date.rb +3 -2
- data/lib/rails_com/engine.rb +3 -5
- data/lib/rails_com/helpers/model_helper.rb +10 -8
- data/lib/rails_com/rails_ext/activestorage_attached.rb +1 -1
- data/lib/rails_com/rails_ext/attached_macros.rb +21 -0
- data/lib/rails_com/rails_ext/attachment_transfer.rb +3 -1
- data/lib/rails_com/rails_ext/errors.rb +4 -0
- data/lib/rails_com/rails_ext/template_renderer.rb +15 -0
- data/lib/rails_com/utils/babel.rb +38 -0
- data/lib/rails_com/utils/time_helper.rb +9 -4
- data/lib/rails_com/version.rb +2 -2
- data/lib/templates/erb/scaffold/edit.html.erb.tt +2 -2
- data/lib/templates/erb/scaffold/new.html.erb.tt +2 -2
- data/lib/templates/erb/scaffold/show.html.erb.tt +2 -2
- metadata +39 -14
- data/app/assets/javascripts/rails_com/common.js +0 -38
- data/app/controllers/concerns/the_common_api.rb +0 -41
- data/app/views/active_storage/attachments/_image_item.html.erb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d89a903e9f829ba767afbef9f90d9a7ddf635ce8d108223ca745f9dc6578f48f
|
4
|
+
data.tar.gz: 389b8a92919cda43adc6024090f3c8aa67bfb33aaa3d2aaf710e27e0235b31e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d0616448bc813c6da2eb8794f2a5894bb671bf2e2a47cf0231bd46d30814046b25d7737ecb7b26f5df89cc40e013fed5731b1ab80722ec8c84bcf0b9570af34
|
7
|
+
data.tar.gz: 85f715d2616e82f7fba685963964524c71b49e6575a217ea6b1022bf7ee3c4e10640578fe14210f0818d399187a3432582f1bc612d05db5c35e950aac1fd309f
|
data/README.md
CHANGED
data/Rakefile
CHANGED
@@ -1,9 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
rescue LoadError
|
4
|
-
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
-
end
|
6
|
-
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'pry'
|
7
3
|
require 'sdoc'
|
8
4
|
require 'rdoc/task'
|
9
5
|
|
@@ -13,22 +9,13 @@ RDoc::Task.new(:sdoc) do |rdoc|
|
|
13
9
|
rdoc.options << '--format=sdoc'
|
14
10
|
rdoc.template = 'rails'
|
15
11
|
rdoc.rdoc_files.include('README.md')
|
12
|
+
rdoc.rdoc_files.include('app/**/*.rb')
|
16
13
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
17
14
|
end
|
18
15
|
|
19
|
-
APP_RAKEFILE = File.expand_path(
|
16
|
+
APP_RAKEFILE = File.expand_path('test/dummy/Rakefile', __dir__)
|
20
17
|
load 'rails/tasks/engine.rake'
|
21
18
|
load 'rails/tasks/statistics.rake'
|
22
19
|
|
23
20
|
require 'bundler/gem_tasks'
|
24
|
-
require 'rake/testtask'
|
25
|
-
|
26
|
-
Rake::TestTask.new(:test) do |t|
|
27
|
-
t.libs << 'lib'
|
28
|
-
t.libs << 'test'
|
29
|
-
t.pattern = 'test/**/*_test.rb'
|
30
|
-
t.verbose = false
|
31
|
-
end
|
32
|
-
|
33
21
|
|
34
|
-
task default: :test
|
Binary file
|
@@ -1,3 +1,45 @@
|
|
1
1
|
//= require rails-ujs
|
2
2
|
//= require turbolinks
|
3
|
-
//=
|
3
|
+
//= require stimulus
|
4
|
+
//= require activestorage
|
5
|
+
//= require_self
|
6
|
+
|
7
|
+
function timeForLocalized(){
|
8
|
+
$('time[data-localized!="true"]').each(function(){
|
9
|
+
if (this.textContent.length > 0) {
|
10
|
+
var format = this.dataset['format'] || 'YYYY-MM-DD HH:mm:ss';
|
11
|
+
this.textContent = moment.utc(this.textContent).local().format(format);
|
12
|
+
this.dataset['localized'] = 'true'
|
13
|
+
}
|
14
|
+
})
|
15
|
+
}
|
16
|
+
|
17
|
+
function clickCallback(e) {
|
18
|
+
if (e.target.tagName !== 'A') {
|
19
|
+
return;
|
20
|
+
}
|
21
|
+
(new Date).getTimezoneOffset();
|
22
|
+
}
|
23
|
+
//document.addEventListener('click', clickCallback, false);
|
24
|
+
|
25
|
+
function htmlToElement(html_str) {
|
26
|
+
var template = document.createElement('template');
|
27
|
+
template.innerHTML = html_str.trim();
|
28
|
+
return template.content.firstChild;
|
29
|
+
}
|
30
|
+
|
31
|
+
document.addEventListener('DOMContentLoaded', function() {
|
32
|
+
timeForLocalized()
|
33
|
+
});
|
34
|
+
document.addEventListener('turbolinks:load', function() {
|
35
|
+
timeForLocalized()
|
36
|
+
});
|
37
|
+
document.addEventListener('turbolinks:visit', function() {
|
38
|
+
timeForLocalized()
|
39
|
+
});
|
40
|
+
|
41
|
+
document.addEventListener('turbolinks:request-start', function(event) {
|
42
|
+
var xhr = event.data.xhr;
|
43
|
+
var offset = (new Date).getTimezoneOffset();
|
44
|
+
xhr.setRequestHeader('Utc-Offset', offset);
|
45
|
+
});
|
data/{lib/assets/javascripts/input-attachment.js → app/assets/javascripts/rails_com/attachment.js}
RENAMED
@@ -3,129 +3,19 @@
|
|
3
3
|
|
4
4
|
/*
|
5
5
|
* Input Field with Attachment
|
6
|
-
*
|
7
|
-
* Author: mingyuan.qin
|
8
|
-
* Contact: mingyuan0715@foxmail.com
|
6
|
+
* based on https://github.com/Rovak/InlineAttachment/blob/master/LICENSE
|
9
7
|
*/
|
10
8
|
|
11
9
|
(function(document, window) {
|
12
10
|
'use strict';
|
13
11
|
|
14
12
|
var InputAttachment = function(options) {
|
15
|
-
this.settings =
|
16
|
-
this.editor =
|
13
|
+
this.settings = Object.assign(options, InputAttachment.defaults);
|
14
|
+
this.editor = this.settings['editor'];
|
17
15
|
this.filenameTag = '{filename}';
|
18
16
|
this.lastValue = null;
|
19
17
|
};
|
20
18
|
|
21
|
-
/**
|
22
|
-
* Will holds the available editors
|
23
|
-
*
|
24
|
-
* @type {Object}
|
25
|
-
*/
|
26
|
-
InputAttachment.editors = {
|
27
|
-
|
28
|
-
initEditor: function(input) {
|
29
|
-
|
30
|
-
return {
|
31
|
-
getValue: function() {
|
32
|
-
return input.value;
|
33
|
-
},
|
34
|
-
|
35
|
-
insertValue: function(val) {
|
36
|
-
InputAttachment.util.insertTextAtCursor(input, val);
|
37
|
-
},
|
38
|
-
|
39
|
-
setValue: function(val) {
|
40
|
-
input.value = val;
|
41
|
-
}
|
42
|
-
}
|
43
|
-
}
|
44
|
-
};
|
45
|
-
|
46
|
-
/**
|
47
|
-
* Utility functions
|
48
|
-
*/
|
49
|
-
InputAttachment.util = {
|
50
|
-
|
51
|
-
/**
|
52
|
-
* Simple function to merge the given objects
|
53
|
-
*
|
54
|
-
* @param {Object[]} object Multiple object parameters
|
55
|
-
* @returns {Object}
|
56
|
-
*/
|
57
|
-
merge: function() {
|
58
|
-
var result = {};
|
59
|
-
for (var i = arguments.length - 1; i >= 0; i--) {
|
60
|
-
var obj = arguments[i];
|
61
|
-
for (var k in obj) {
|
62
|
-
if (obj.hasOwnProperty(k)) {
|
63
|
-
result[k] = obj[k];
|
64
|
-
}
|
65
|
-
}
|
66
|
-
}
|
67
|
-
return result;
|
68
|
-
},
|
69
|
-
|
70
|
-
/**
|
71
|
-
* Append a line of text at the bottom, ensuring there aren't unnecessary newlines
|
72
|
-
*
|
73
|
-
* @param {String} appended Current content
|
74
|
-
* @param {String} previous Value which should be appended after the current content
|
75
|
-
*/
|
76
|
-
appendInItsOwnLine: function(previous, appended) {
|
77
|
-
return (previous + "\n\n[[D]]" + appended)
|
78
|
-
.replace(/(\n{2,})\[\[D\]\]/, "\n\n")
|
79
|
-
.replace(/^(\n*)/, "");
|
80
|
-
},
|
81
|
-
|
82
|
-
/**
|
83
|
-
* Inserts the given value at the current cursor position of the textarea element
|
84
|
-
*
|
85
|
-
* @param {HTMLElement} el
|
86
|
-
* @param {String} text Text which will be inserted at the cursor position
|
87
|
-
*/
|
88
|
-
insertTextAtCursor: function(el, text) {
|
89
|
-
var scrollPos = el.scrollTop,
|
90
|
-
strPos = 0,
|
91
|
-
browser = false,
|
92
|
-
range;
|
93
|
-
|
94
|
-
if ((el.selectionStart || el.selectionStart === '0')) {
|
95
|
-
browser = 'ff';
|
96
|
-
} else if (document.selection) {
|
97
|
-
browser = 'ie';
|
98
|
-
}
|
99
|
-
|
100
|
-
if (browser === 'ie') {
|
101
|
-
el.focus();
|
102
|
-
range = document.selection.createRange();
|
103
|
-
range.moveStart('character', -el.value.length);
|
104
|
-
strPos = range.text.length;
|
105
|
-
} else if (browser === 'ff') {
|
106
|
-
strPos = el.selectionStart;
|
107
|
-
}
|
108
|
-
|
109
|
-
var front = (el.value).substring(0, strPos);
|
110
|
-
var back = (el.value).substring(strPos, el.value.length);
|
111
|
-
el.value = front + text + back;
|
112
|
-
strPos = strPos + text.length;
|
113
|
-
if (browser === 'ie') {
|
114
|
-
el.focus();
|
115
|
-
range = document.selection.createRange();
|
116
|
-
range.moveStart('character', -el.value.length);
|
117
|
-
range.moveStart('character', strPos);
|
118
|
-
range.moveEnd('character', 0);
|
119
|
-
range.select();
|
120
|
-
} else if (browser === "ff") {
|
121
|
-
el.selectionStart = strPos;
|
122
|
-
el.selectionEnd = strPos;
|
123
|
-
el.focus();
|
124
|
-
}
|
125
|
-
el.scrollTop = scrollPos;
|
126
|
-
}
|
127
|
-
};
|
128
|
-
|
129
19
|
/**
|
130
20
|
* Default configuration options
|
131
21
|
*
|
@@ -210,7 +100,9 @@
|
|
210
100
|
/**
|
211
101
|
* Triggers when a file is dropped or pasted
|
212
102
|
*/
|
213
|
-
onFileReceived: function() {
|
103
|
+
onFileReceived: function() {
|
104
|
+
|
105
|
+
},
|
214
106
|
|
215
107
|
/**
|
216
108
|
* Custom upload handler
|
@@ -271,7 +163,7 @@
|
|
271
163
|
formData.append(settings.uploadFieldName, file, remoteFilename);
|
272
164
|
|
273
165
|
// Append the extra parameters to the form data
|
274
|
-
if (typeof settings.extraParams ===
|
166
|
+
if (typeof settings.extraParams === 'object') {
|
275
167
|
for (var key in settings.extraParams) {
|
276
168
|
if (settings.extraParams.hasOwnProperty(key)) {
|
277
169
|
formData.append(key, settings.extraParams[key]);
|
@@ -305,36 +197,18 @@
|
|
305
197
|
};
|
306
198
|
|
307
199
|
InputAttachment.prototype.previewFile = function(file, obj) {
|
308
|
-
var fileList = document.getElementById(this.settings.previewDiv)
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
}
|
318
|
-
} else if(window.FileReader){
|
319
|
-
//opera不支持createObjectURL/revokeObjectURL方法。我们用FileReader对象来处理
|
320
|
-
var reader = new FileReader();
|
321
|
-
reader.readAsDataURL(file);
|
322
|
-
reader.onload = function(e){
|
323
|
-
img.src = this.result;
|
324
|
-
}
|
325
|
-
}else{
|
326
|
-
//ie
|
327
|
-
obj.select();
|
328
|
-
obj.blur();
|
329
|
-
var nfile = document.selection.createRange().text;
|
330
|
-
document.selection.empty();
|
331
|
-
img.src = nfile;
|
332
|
-
img.onload=function(e){
|
333
|
-
|
334
|
-
}
|
200
|
+
var fileList = document.getElementById(this.settings.previewDiv)
|
201
|
+
var template = document.createElement('template');
|
202
|
+
template.innerHTML = fileList.firstElementChild.outerHTML.trim();
|
203
|
+
var img_div = template.content.firstChild;
|
204
|
+
var img = img_div.lastElementChild;
|
205
|
+
|
206
|
+
img.src = window.URL.createObjectURL(file); //创建一个object URL,并不是你的本地路径
|
207
|
+
img.onload = function(e) {
|
208
|
+
window.URL.revokeObjectURL(this.src); //图片加载后,释放object URL
|
335
209
|
}
|
336
210
|
|
337
|
-
fileList.appendChild(
|
211
|
+
fileList.appendChild(img_div);
|
338
212
|
};
|
339
213
|
|
340
214
|
/**
|
@@ -369,8 +243,7 @@
|
|
369
243
|
} else {
|
370
244
|
newValue = this.settings.urlText.replace(this.filenameTag, filename);
|
371
245
|
}
|
372
|
-
|
373
|
-
this.editor.setValue(text);
|
246
|
+
this.editor.input.value.replace(this.lastValue, newValue);
|
374
247
|
this.settings.onFileUploaded.call(this, filename, result);
|
375
248
|
}
|
376
249
|
}
|
@@ -385,8 +258,7 @@
|
|
385
258
|
*/
|
386
259
|
InputAttachment.prototype.onFileUploadError = function(xhr) {
|
387
260
|
if (this.settings.onFileUploadError.call(this, xhr) !== false) {
|
388
|
-
|
389
|
-
this.editor.setValue(text);
|
261
|
+
this.editor.input.value.replace(this.lastValue, '');
|
390
262
|
}
|
391
263
|
};
|
392
264
|
|
@@ -399,7 +271,10 @@
|
|
399
271
|
InputAttachment.prototype.onFileInserted = function(file) {
|
400
272
|
if (this.settings.onFileReceived.call(this, file) !== false) {
|
401
273
|
this.lastValue = this.settings.progressText;
|
402
|
-
|
274
|
+
|
275
|
+
var scrollPos = el.scrollTop
|
276
|
+
el.value = this.lastValue;
|
277
|
+
el.scrollTop = scrollPos;
|
403
278
|
}
|
404
279
|
};
|
405
280
|
|
@@ -538,5 +413,4 @@
|
|
538
413
|
|
539
414
|
window.attachToInput = attachToInput;
|
540
415
|
window.attachToPreview = attachToPreview;
|
541
|
-
|
542
|
-
})(document, window);
|
416
|
+
})(document, window);
|
@@ -0,0 +1,17 @@
|
|
1
|
+
//= require ./attachment
|
2
|
+
|
3
|
+
class PictureController extends Stimulus.Controller {
|
4
|
+
greet() {
|
5
|
+
console.log('Hellos, Stimulus!', this.element)
|
6
|
+
}
|
7
|
+
|
8
|
+
connect() {
|
9
|
+
console.log('Connects, Stimulus!', this.element)
|
10
|
+
attachToPreview({
|
11
|
+
fileInput: 'picture_file'
|
12
|
+
});
|
13
|
+
}
|
14
|
+
}
|
15
|
+
PictureController.targets = ['src']
|
16
|
+
const application = Stimulus.Application.start()
|
17
|
+
application.register('picture', PictureController)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class
|
1
|
+
class ActiveStorageExt::Admin::AttachmentsController < ActiveStorageExt::Admin::BaseController
|
2
2
|
before_action :set_attachment, only: [:destroy]
|
3
3
|
|
4
4
|
def destroy
|
@@ -10,4 +10,4 @@ class ActiveStorage::AttachmentsController < ActiveStorage::BaseController
|
|
10
10
|
@attachment = ActiveStorage::Attachment.find(params[:id])
|
11
11
|
end
|
12
12
|
|
13
|
-
end
|
13
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
class ActiveStorageExt::Admin::BlobDefaultsController < ActiveStorageExt::Admin::BaseController
|
2
|
+
before_action :set_blob_default, only: [:show, :edit, :update, :destroy]
|
3
|
+
|
4
|
+
def index
|
5
|
+
@blob_defaults = ActiveStorage::BlobDefault.page(params[:page])
|
6
|
+
end
|
7
|
+
|
8
|
+
def new
|
9
|
+
@blob_default = ActiveStorage::BlobDefault.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def create
|
13
|
+
@blob_default = ActiveStorage::BlobDefault.new(blob_default_params)
|
14
|
+
|
15
|
+
if @blob_default.save
|
16
|
+
redirect_to rails_ext_blob_defaults_url, notice: 'Blob default was successfully created.'
|
17
|
+
else
|
18
|
+
render :new
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def show
|
23
|
+
end
|
24
|
+
|
25
|
+
def edit
|
26
|
+
end
|
27
|
+
|
28
|
+
def update
|
29
|
+
if @blob_default.update(blob_default_params)
|
30
|
+
redirect_to rails_ext_blob_defaults_url, notice: 'Blob default was successfully updated.'
|
31
|
+
else
|
32
|
+
render :edit
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def destroy
|
37
|
+
@blob_default.destroy
|
38
|
+
redirect_to rails_ext_blob_defaults_url, notice: 'Blob default was successfully destroyed.'
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
def set_blob_default
|
43
|
+
@blob_default = ActiveStorage::BlobDefault.find(params[:id])
|
44
|
+
end
|
45
|
+
|
46
|
+
def blob_default_params
|
47
|
+
params.fetch(:blob_default, {}).permit(
|
48
|
+
:record_class,
|
49
|
+
:name,
|
50
|
+
:file
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
class ActiveStorageExt::Admin::BlobsController < ActiveStorageExt::Admin::BaseController
|
2
|
+
before_action :set_blob, only: [:destroy]
|
3
|
+
|
4
|
+
def index
|
5
|
+
q_params = {}.with_indifferent_access
|
6
|
+
q_params.merge params.fetch(:q, {}).permit(:key, :filename)
|
7
|
+
@blobs = ActiveStorage::Blob.default_where(q_params).order(id: :desc).page(params[:page])
|
8
|
+
end
|
9
|
+
|
10
|
+
def unattached
|
11
|
+
q_params = {}.with_indifferent_access
|
12
|
+
q_params.merge params.fetch(:q, {}).permit(:key, :filename)
|
13
|
+
@blobs = ActiveStorage::Blob.unattached.default_where(q_params).order(id: :desc).page(params[:page])
|
14
|
+
render :index
|
15
|
+
end
|
16
|
+
|
17
|
+
def new
|
18
|
+
@blob = ActiveStorage::Blob.new(filename: '')
|
19
|
+
end
|
20
|
+
|
21
|
+
def create
|
22
|
+
@blob = ActiveStorage::Blob.build_after_upload(io: blob_params[:io].tempfile, filename: blob_params[:io].original_filename)
|
23
|
+
|
24
|
+
if @blob.save
|
25
|
+
redirect_to rails_ext_blobs_url, notice: 'Blob was successfully created.'
|
26
|
+
else
|
27
|
+
render :new
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def destroy
|
32
|
+
@blob.purge
|
33
|
+
redirect_to rails_ext_blobs_url, notice: 'Blob was successfully destroyed.'
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
def set_blob
|
38
|
+
@blob = ActiveStorage::Blob.find(params[:id])
|
39
|
+
end
|
40
|
+
|
41
|
+
def blob_params
|
42
|
+
params.fetch(:blob, {}).permit(
|
43
|
+
:key,
|
44
|
+
:io
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|