1require 'csv' |
|
3class Admin::LogsController < Admin::AdminController |
|
4 before_action :fetch_logs |
|
5 before_action :fetch_signature |
|
6 before_action :fetch_petition |
|
8 after_action :set_content_disposition, if: :csv_request? |
|
10 def show |
|
11 respond_to do |format| |
|
12 format.html
|
|
13 format.csv
|
|
14 end |
|
15 end |
|
17 private
|
|
19 def fetch_logs |
|
20 @logs = SignatureLogs.find(params[:signature_id]) |
|
21 end |
|
23 def fetch_signature |
|
24 @signature = @logs.signature |
|
25 end |
|
27 def fetch_petition |
|
28 @petition = @signature.petition |
|
29 end |
|
31 def csv_filename |
|
32 "signature-#{@signature.id}-access-logs.csv" |
|
33 end |
|
35 def set_content_disposition |
|
36 response.headers['Content-Disposition'] = "attachment; filename=#{csv_filename}" |
|
37 end |
|
38end |