Class: LibrariesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- LibrariesController
- Defined in:
- app/controllers/libraries_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #preview ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/controllers/libraries_controller.rb', line 24 def create Library @library = Library.create(library_params) @library.tag_regex = params[:tag_regex] if @library.valid? @library.detect_filesystem_changes_later @library.make_default if SiteSettings.default_library.nil? redirect_to @library, notice: t(".success") else flash.now[:alert] = t(".failure") render :new, status: :unprocessable_content end end |
#destroy ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'app/controllers/libraries_controller.rb', line 51 def destroy begin @library.destroy Library.first&.make_default if @library.default? rescue Shrine::Error # Not ideal, but file after_commit callbacks explode if the library has gone nil end redirect_to settings_libraries_path, notice: t(".success") end |
#edit ⇒ Object
21 22 |
# File 'app/controllers/libraries_controller.rb', line 21 def edit end |
#index ⇒ Object
6 7 8 9 |
# File 'app/controllers/libraries_controller.rb', line 6 def index redirect_to new_library_path and return if Library.all.empty? # rubocop:disable Pundit/UsePolicyScope render layout: "settings" end |
#new ⇒ Object
15 16 17 18 19 |
# File 'app/controllers/libraries_controller.rb', line 15 def new Library @library = Library.new @title = t("libraries.general.new") end |
#preview ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'app/controllers/libraries_controller.rb', line 61 def preview # Create temporary library; we're not saving it @library = params[:id] ? Library.find_param(params[:id]) : Library.new(path: params[:path]) @library.path_template = params[:template] @library. = (params[:enabled] === "true") @library render Components::PathTemplatePreview.new(library: @library), layout: nil end |
#show ⇒ Object
11 12 13 |
# File 'app/controllers/libraries_controller.rb', line 11 def show redirect_to models_path(library: @library) end |
#update ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/controllers/libraries_controller.rb', line 38 def update @library.update(library_params) = library_params[:tag_regex]&.reject(&:empty?) @library.tag_regex = if @library.save @library.make_default if params.dig("library", "default") == "1" redirect_to settings_libraries_path, notice: t(".success") else flash.now[:alert] = t(".failure") render :edit, status: :unprocessable_content end end |