Class: EventExportFilesController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/event_export_files_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /event_export_files POST /event_export_files.json



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/controllers/event_export_files_controller.rb', line 57

def create
  @event_export_file = EventExportFile.new(event_export_file_params)
  @event_export_file.user = current_user

  respond_to do |format|
    if @event_export_file.save
      if @event_export_file.mode == 'export'
        EventExportFileJob.perform_later(@event_export_file)
      end
      format.html { redirect_to @event_export_file, notice: t('export.successfully_created', model: t('activerecord.models.event_export_file')) }
      format.json { render json: @event_export_file, status: :created, location: @event_export_file }
    else
      format.html { render action: "new" }
      format.json { render json: @event_export_file.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /event_export_files/1 DELETE /event_export_files/1.json



94
95
96
97
98
99
100
101
# File 'app/controllers/event_export_files_controller.rb', line 94

def destroy
  @event_export_file.destroy

  respond_to do |format|
    format.html { redirect_to event_export_files_url }
    format.json { head :no_content }
  end
end

#editObject

GET /event_export_files/1/edit



52
53
# File 'app/controllers/event_export_files_controller.rb', line 52

def edit
end

#indexObject

GET /event_export_files GET /event_export_files.json



7
8
9
10
11
12
13
14
# File 'app/controllers/event_export_files_controller.rb', line 7

def index
  @event_export_files = EventExportFile.order('id DESC').page(params[:page])

  respond_to do |format|
    format.html # index.html.erb
    format.json { render json: @event_export_files }
  end
end

#newObject

GET /event_export_files/new GET /event_export_files/new.json



41
42
43
44
45
46
47
48
49
# File 'app/controllers/event_export_files_controller.rb', line 41

def new
  @event_export_file = EventExportFile.new
  @event_export_file.user = current_user

  respond_to do |format|
    format.html # new.html.erb
    format.json { render json: @event_export_file }
  end
end

#showObject

GET /event_export_files/1 GET /event_export_files/1.json



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/event_export_files_controller.rb', line 18

def show
  if @event_export_file.event_export.path
    unless ENV['ENJU_STORAGE'] == 's3'
      file = @event_export_file.event_export.path
    end
  end

  respond_to do |format|
    format.html # show.html.erb
    format.json { render json: @event_export_file }
    format.download {
      if ENV['ENJU_STORAGE'] == 's3'
        send_data Faraday.get(@event_export_file.event_export.expiring_url).body.force_encoding('UTF-8'),
          filename: File.basename(@event_export_file.event_export_file_name), type: 'application/octet-stream'
      else
        send_file file, filename: @event_export_file.event_export_file_name, type: 'application/octet-stream'
      end
    }
  end
end

#updateObject

PUT /event_export_files/1 PUT /event_export_files/1.json



77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'app/controllers/event_export_files_controller.rb', line 77

def update
  respond_to do |format|
    if @event_export_file.update(event_export_file_params)
      if @event_export_file.mode == 'export'
        EventExportFileJob.perform_later(@event_export_file)
      end
      format.html { redirect_to @event_export_file, notice: t('controller.successfully_updated', model: t('activerecord.models.event_export_file')) }
      format.json { head :no_content }
    else
      format.html { render action: "edit" }
      format.json { render json: @event_export_file.errors, status: :unprocessable_entity }
    end
  end
end