Class: BillingReportsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/billing_reports_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#block_api_access, #clean_params_from_check, #evil_parameter_hack!, #extract_header_info, #set_cache_disabled!

Instance Method Details

#billing_report_paramsObject


19
20
21
# File 'app/controllers/billing_reports_controller.rb', line 19

def billing_report_params
  params.require(:billing_report).permit(:start_date, :end_date, :file_name) if params[:billing_report].present?
end

#createObject


6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/controllers/billing_reports_controller.rb', line 6

def create
  @billing_report = Billing::Report.new(billing_report_params.merge(fields: Billing.configuration.fields))
  if @billing_report.valid?
    send_data @billing_report.data,
              type: 'text',
              filename: "#{@billing_report.file_name}.bif",
              disposition: 'attachment'
  else
    flash.now[:error] = @billing_report.errors.full_messages.join(', ')
    render :new
  end
end

#newObject


2
3
4
# File 'app/controllers/billing_reports_controller.rb', line 2

def new
  @billing_report = Billing::Report.new(billing_report_params)
end