Skip to content

Commit

Permalink
Map route to a controller action.
Browse files Browse the repository at this point in the history
Provide controller action body - execute csv exporter.
  • Loading branch information
tomdonarski committed Nov 24, 2023
1 parent 7c538d2 commit 4e65318
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions app/controllers/spree/admin/promotion_batches_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ def show
format.js { render layout: false } if request.xhr?
end
end

def csv_export
send_data PromoCodesExporter.new(params).call,
filename: "promo_codes_from_batch_id_#{params[:id]}.csv",
disposition: :attachment,
type: "text/csv"
end
end
end
end
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

resources :promotion_batches do
member do
get :csv_export
get :csv_export, to: 'promotion_batches#csv_export'
end
end

Expand Down

0 comments on commit 4e65318

Please sign in to comment.