Class: AgentImportFilesController

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

Instance Method Summary collapse

Instance Method Details

#createObject

POST /agent_import_files POST /agent_import_files.json



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

def create
  @agent_import_file = AgentImportFile.new(agent_import_file_params)
  @agent_import_file.user = current_user

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

#destroyObject

DELETE /agent_import_files/1 DELETE /agent_import_files/1.json



92
93
94
95
96
97
98
99
# File 'app/controllers/agent_import_files_controller.rb', line 92

def destroy
  @agent_import_file.destroy

  respond_to do |format|
    format.html { redirect_to agent_import_files_url, notice: t('controller.successfully_deleted', model: t('activerecord.models.agent_import_file')) }
    format.json { head :no_content }
  end
end

#editObject

GET /agent_import_files/1/edit



50
51
# File 'app/controllers/agent_import_files_controller.rb', line 50

def edit
end

#indexObject

GET /agent_import_files GET /agent_import_files.json



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

def index
  @agent_import_files = AgentImportFile.page(params[:page])

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

#newObject

GET /agent_import_files/new GET /agent_import_files/new.json



40
41
42
43
44
45
46
47
# File 'app/controllers/agent_import_files_controller.rb', line 40

def new
  @agent_import_file = AgentImportFile.new

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

#showObject

GET /agent_import_files/1 GET /agent_import_files/1.json



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

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

  respond_to do |format|
    format.html # show.html.erb
    format.json { render json: @agent_import_file }
    format.download {
      if ENV['ENJU_STORAGE'] == 's3'
        redirect_to @agent_import_file.agent_import.expiring_url(10)
      else
        send_file file, filename: @agent_import_file.agent_import_file_name, type: 'application/octet-stream'
      end
    }
  end
end

#updateObject

PUT /agent_import_files/1 PUT /agent_import_files/1.json



75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'app/controllers/agent_import_files_controller.rb', line 75

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