Class: Headmin::MediaController
Instance Method Summary
collapse
Methods included from Pagination
#page, #paginate, #per_page
Instance Method Details
#create ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'app/controllers/headmin/media_controller.rb', line 22
def create
blobs = []
media_params[:files].reject { |c| c.blank? }.each do |file|
blobs << ActiveStorage::Blob.create_and_upload!(io: file, filename: file.original_filename)
end
respond_to do |format|
format.turbo_stream {
@blobs = blobs
}
format.html { redirect_to root_path }
end
end
|
#index ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'app/controllers/headmin/media_controller.rb', line 5
def index
@blobs =
ActiveStorage::Blob
.not_attached_to_variant
.by_mimetypes_string(media_params[:mimetype])
.order(created_at: :desc)
.group(:id)
.all
@blobs = paginate(@blobs)
@mimetypes = media_params[:mimetype]
respond_to do |format|
format.html
format.turbo_stream
end
end
|
#show ⇒ Object
36
37
38
|
# File 'app/controllers/headmin/media_controller.rb', line 36
def show
@blob = ActiveStorage::Blob.find(params[:id])
end
|
#thumbnail ⇒ Object
48
49
50
|
# File 'app/controllers/headmin/media_controller.rb', line 48
def thumbnail
@blob = ActiveStorage::Blob.find(params[:id])
end
|
#update ⇒ Object
40
41
42
43
44
45
46
|
# File 'app/controllers/headmin/media_controller.rb', line 40
def update
@blob = ActiveStorage::Blob.find(params[:id])
media_item_params[:filename] = media_item_params[:filename] + "." + @blob.filename.to_s.rpartition(".").last
if @blob.update(media_item_params)
flash.now[:notice] = t("admin.flash.updated", name: @blob.filename)
end
end
|