Class: Avo::MediaLibraryController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- BaseApplicationController
- ApplicationController
- Avo::MediaLibraryController
- Includes:
- Pagy::Method
- Defined in:
- app/controllers/avo/media_library_controller.rb
Constant Summary
Constants included from Concerns::FindAssociationField
Concerns::FindAssociationField::ASSOCIATIONS
Instance Method Summary collapse
- #attach ⇒ Object
- #destroy ⇒ Object
- #extract_initials(filename) ⇒ Object
- #index ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Methods inherited from BaseApplicationController
#exception_logger, #turbo_frame_request?
Methods included from Concerns::FindAssociationField
Methods included from Concerns::Breadcrumbs
#add_breadcrumb, #avo_breadcrumbs
Methods included from UrlHelpers
#edit_resource_path, #new_resource_path, #preview_resource_path, #related_resources_path, #resource_attach_path, #resource_detach_path, #resource_path, #resource_view_path, #resources_path
Methods included from ApplicationHelper
#a_button, #a_link, #body_classes, #button_classes, #chart_color, #container_classes, #d, #decode_filter_params, #e, #editor_file_path, #editor_url, #empty_state, #encode_filter_params, #frame_id, #get_model_class, #input_classes, #mount_path, #number_to_social, #possibly_rails_authentication?, #render_license_warning, #root_path_without_url, #rtl?, #text_direction, #ui, #wrap_in_modal
Methods included from ResourcesHelper
#field_wrapper, #filter_wrapper, #index_field_wrapper, #item_selector_data_attributes, #record_path, #record_title, #resource_for_record, #resource_grid, #resource_show_path, #resource_table
Methods included from CommonController
#default_url_options, #extra_default_url_options
Methods included from InitializesAvo
#_current_user, #context, #init_app
Methods included from Concerns::SafeCall
Instance Method Details
#attach ⇒ Object
42 43 44 45 46 |
# File 'app/controllers/avo/media_library_controller.rb', line 42 def attach @attaching = true render :index end |
#destroy ⇒ Object
30 31 32 33 34 35 |
# File 'app/controllers/avo/media_library_controller.rb', line 30 def destroy @blob = ActiveStorage::Blob.find(params[:id]) @blob.destroy! redirect_to avo.media_library_index_path end |
#extract_initials(filename) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'app/controllers/avo/media_library_controller.rb', line 19 def extract_initials(filename) # Remove file extension name_without_ext = File.basename(filename, File.extname(filename)) # Split by spaces and take first 2 words words = name_without_ext.split(" ").first(2) # Extract first character of each word and join words.map { |word| word[0] }.join("").upcase end |
#index ⇒ Object
7 8 9 10 |
# File 'app/controllers/avo/media_library_controller.rb', line 7 def index @attaching = false title: "Media Library", initials: "ML" end |
#show ⇒ Object
12 13 14 15 16 17 |
# File 'app/controllers/avo/media_library_controller.rb', line 12 def show @blob = ActiveStorage::Blob.find(params[:id]) title: "Media Library", path: avo.media_library_index_path, initials: "ML" title: @blob.filename.to_s, path: nil, initials: extract_initials(@blob.filename.to_s) end |
#update ⇒ Object
37 38 39 40 |
# File 'app/controllers/avo/media_library_controller.rb', line 37 def update @blob = ActiveStorage::Blob.find(params[:id]) @blob.update!(blob_params) end |