Class: QuickAdmin::ResourcesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- QuickAdmin::ResourcesController
- Defined in:
- app/controllers/quick_admin/resources_controller.rb
Instance Method Summary collapse
- #attachment ⇒ Object
- #bulk_destroy ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#attachment ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/controllers/quick_admin/resources_controller.rb', line 20 def field = params[:field] = @resource.public_send(field) if @resource.respond_to?(field) @blob = if params[:signed_id].present? begin ActiveStorage::Blob.find_signed(params[:signed_id]) rescue ActiveSupport::MessageVerifier::InvalidSignature nil end else &.blob end respond_to do |format| format.html { render :attachment } format.turbo_stream { render :attachment } end rescue => e Rails.logger.error "Attachment error: #{e.}" @blob = nil respond_to do |format| format.html { render :attachment } format.turbo_stream { render :attachment } end end |
#bulk_destroy ⇒ Object
95 96 97 98 99 100 101 102 103 104 |
# File 'app/controllers/quick_admin/resources_controller.rb', line 95 def bulk_destroy ids = params[:ids] || [] resource_class.where(id: ids).destroy_all respond_to do |format| format.html { redirect_to quick_admin.resources_path(resource_name), notice: "#{ids.count} records deleted successfully." } format.turbo_stream { refresh_resources_list } format.any { refresh_resources_list; render :bulk_destroy, formats: :turbo_stream } end end |
#create ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/controllers/quick_admin/resources_controller.rb', line 52 def create @resource = resource_class.new(resource_params) if @resource.save respond_to do |format| format.html { redirect_to quick_admin.resources_path(resource_name), notice: 'Record created successfully.' } format.turbo_stream { refresh_resources_list } format.any { refresh_resources_list; render :create, formats: :turbo_stream } end else respond_to do |format| format.html { render :new } format.turbo_stream { render :new } end end end |
#destroy ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'app/controllers/quick_admin/resources_controller.rb', line 86 def destroy @resource.destroy respond_to do |format| format.html { redirect_to quick_admin.resources_path(resource_name), notice: 'Record deleted successfully.' } format.turbo_stream { refresh_resources_list } format.any { refresh_resources_list; render :destroy, formats: :turbo_stream } end end |
#edit ⇒ Object
69 |
# File 'app/controllers/quick_admin/resources_controller.rb', line 69 def edit; end |
#index ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'app/controllers/quick_admin/resources_controller.rb', line 8 def index @pagy, @resources = pagy(filtered_resources, items: QuickAdmin.config.per_page) respond_to do |format| format.html if params[:search].present? || params[:filter].present? format.turbo_stream format.any { render :index, formats: :turbo_stream } end end end |
#new ⇒ Object
48 49 50 |
# File 'app/controllers/quick_admin/resources_controller.rb', line 48 def new @resource = resource_class.new end |
#show ⇒ Object
46 |
# File 'app/controllers/quick_admin/resources_controller.rb', line 46 def show; end |
#update ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/controllers/quick_admin/resources_controller.rb', line 71 def update if @resource.update(resource_params) respond_to do |format| format.html { redirect_to quick_admin.resources_path(resource_name), notice: 'Record updated successfully.' } format.turbo_stream { refresh_resources_list } format.any { refresh_resources_list; render :update, formats: :turbo_stream } end else respond_to do |format| format.html { render :edit } format.turbo_stream { render :edit } end end end |