Class: Spree::Admin::ExportsController
- Inherits:
-
ResourceController
- Object
- ResourceController
- Spree::Admin::ExportsController
- Includes:
- ActiveStorage::SetCurrent
- Defined in:
- app/controllers/spree/admin/exports_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
Allow raw JSON attributes for STI and metadata Example: { type: ‘SpreeCmCommissioner::Exports::OperatorGuestJsonGzip’, public_metadata: …, exportable_type: ‘Spree::Taxon’, exportable_id: 1 }.
- #destroy ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
Instance Method Details
#create ⇒ Object
Allow raw JSON attributes for STI and metadata Example:
type: 'SpreeCmCommissioner::Exports::OperatorGuestJsonGzip',
public_metadata: {...,
exportable_type: 'Spree::Taxon',
exportable_id: 1
}
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/controllers/spree/admin/exports_controller.rb', line 30 def create # rubocop:disable Metrics/AbcSize attrs = permitted_resource_params.to_h.with_indifferent_access # Parse public_metadata JSON if attrs[:public_metadata].present? begin attrs[:public_metadata] = JSON.parse(attrs[:public_metadata]) if attrs[:public_metadata].is_a?(String) rescue JSON::ParserError => e flash[:error] = "Invalid JSON in public_metadata: #{e.}" return redirect_to new_admin_export_path end end # Parse private_metadata JSON if attrs[:private_metadata].present? begin attrs[:private_metadata] = JSON.parse(attrs[:private_metadata]) if attrs[:private_metadata].is_a?(String) rescue JSON::ParserError => e flash[:error] = "Invalid JSON in private_metadata: #{e.}" return redirect_to new_admin_export_path end end export_class = attrs[:type].constantize export = export_class.new(attrs.except(:type)) if export.save flash[:success] = (export, :successfully_created) else flash[:error] = export.errors..join(', ') end redirect_to admin_exports_path rescue NameError => e flash[:error] = "Invalid export type: #{e.}" redirect_to admin_exports_path end |
#destroy ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'app/controllers/spree/admin/exports_controller.rb', line 68 def destroy if @export.destroy flash[:success] = (@export, :successfully_removed) else flash[:error] = @export.errors..join(', ') end redirect_to admin_exports_path end |
#index ⇒ Object
8 9 10 11 12 13 |
# File 'app/controllers/spree/admin/exports_controller.rb', line 8 def index @exports = SpreeCmCommissioner::Export .order(created_at: :desc) .page(params[:page]) .per(params[:per_page] || 25) end |
#new ⇒ Object
19 20 21 |
# File 'app/controllers/spree/admin/exports_controller.rb', line 19 def new @export = SpreeCmCommissioner::Export.new end |
#show ⇒ Object
15 16 17 |
# File 'app/controllers/spree/admin/exports_controller.rb', line 15 def show # @export is loaded by before_action end |