From 259d91917592d6ab5ea8604da3e2c544d85b81b2 Mon Sep 17 00:00:00 2001 From: viehlieb Date: Tue, 14 Feb 2023 16:54:03 +0100 Subject: [PATCH] add rute and controller method to orders controller --- app/controllers/orders_controller.rb | 15 ++++++++++++++- config/routes.rb | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index cfa7cef6..1e041bf2 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -49,7 +49,7 @@ class OrdersController < ApplicationController send_order_pdf @order, params[:document] end format.csv do - send_data OrderCsv.new(@order).to_csv, filename: @order.name + '.csv', type: 'text/csv' + send_data OrderCsv.new(@order, options= {custom_csv: params[:custom_csv]}).to_csv, filename: @order.name + '.csv', type: 'text/csv' end format.text do send_data OrderTxt.new(@order).to_txt, filename: @order.name + '.txt', type: 'text/plain' @@ -57,6 +57,19 @@ class OrdersController < ApplicationController end end + def custom_csv + @order = Order.find(params[:id]) + @view = (params[:view] || 'default').gsub(/[^-_a-zA-Z0-9]/, '') + @partial = case @view + when 'default' then 'articles' + when 'groups' then 'shared/articles_by/groups' + when 'articles' then 'shared/articles_by/articles' + else 'articles' + end + + render :layout => false + end + # Page to create a new order. def new if params[:order_id] diff --git a/config/routes.rb b/config/routes.rb index 83e65707..b82699ec 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -47,6 +47,7 @@ Rails.application.routes.draw do get :receive post :receive + get :custom_csv get :receive_on_order_article_create get :receive_on_order_article_update end