Class: Panda::CMS::Admin::FilesController
- Inherits:
-
BaseController
- Object
- Panda::Core::Admin::BaseController
- BaseController
- Panda::CMS::Admin::FilesController
show all
- Defined in:
- app/controllers/panda/cms/admin/files_controller.rb
Instance Method Summary
collapse
#set_current_request_details
#active_link?, #block_link_to, #component, #level_indent, #menu_indent, #nav_class, #nav_highlight_colour_classes, #panda_cms_collection, #panda_cms_collection_items, #panda_cms_editor, #panda_cms_feature_enabled?, #panda_cms_form_with, #selected_nav_highlight_colour_classes, #table_indent, #title_tag
Instance Method Details
#create ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'app/controllers/panda/cms/admin/files_controller.rb', line 12
def create
file = params[:image]
return render json: {success: 0} unless file
blob = ActiveStorage::Blob.create_and_upload!(
io: file,
filename: file.original_filename,
content_type: file.content_type
)
render json: {
success: true,
file: {
url: Rails.application.routes.url_helpers.rails_blob_url(blob, only_path: true),
name: blob.filename.to_s,
size: blob.byte_size
}
}
end
|
#index ⇒ Object
7
8
9
10
|
# File 'app/controllers/panda/cms/admin/files_controller.rb', line 7
def index
@files = ActiveStorage::Blob.order(created_at: :desc)
@selected_file = @files.first if @files.any?
end
|