Class: UserExportFilesController

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

Instance Method Summary collapse

Instance Method Details

#createObject

POST /user_export_files POST /user_export_files.json



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

def create
  @user_export_file = UserExportFile.new(user_export_file_params)
  @user_export_file.user = current_user

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

#destroyObject

DELETE /user_export_files/1 DELETE /user_export_files/1.json



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

def destroy
  @user_export_file.destroy

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

#editObject

GET /user_export_files/1/edit



51
52
# File 'app/controllers/user_export_files_controller.rb', line 51

def edit
end

#indexObject

GET /user_export_files GET /user_export_files.json



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

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

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

#newObject

GET /user_export_files/new GET /user_export_files/new.json



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

def new
  @user_export_file = UserExportFile.new
  @user_export_file.user = current_user

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

#showObject

GET /user_export_files/1 GET /user_export_files/1.json



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

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

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

#updateObject

PUT /user_export_files/1 PUT /user_export_files/1.json



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

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