Class: InventoryFilesController

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

Instance Method Summary collapse

Instance Method Details

#createObject

POST /inventory_files POST /inventory_files.json



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

def create
  @inventory_file = InventoryFile.new(inventory_file_params)
  @inventory_file.user = current_user

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

#destroyObject

DELETE /inventory_files/1 DELETE /inventory_files/1.json



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

def destroy
  @inventory_file.destroy

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

#editObject

GET /inventory_files/1/edit



53
54
# File 'app/controllers/inventory_files_controller.rb', line 53

def edit
end

#indexObject

GET /inventory_files GET /inventory_files.json



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

def index
  @inventory_files = InventoryFile.page(params[:page])

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

#newObject

GET /inventory_files/new GET /inventory_files/new.json



43
44
45
46
47
48
49
50
# File 'app/controllers/inventory_files_controller.rb', line 43

def new
  @inventory_file = InventoryFile.new

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

#showObject

GET /inventory_files/1 GET /inventory_files/1.json



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

def show
  if @inventory_file.inventory.path
    unless ENV['ENJU_STORAGE'] == 's3'
      file = @inventory_file.inventory.path
    end
  end
  @inventories = @inventory_file.inventories.page(params[:page])

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

#updateObject

PUT /inventory_files/1 PUT /inventory_files/1.json



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

def update
  respond_to do |format|
    if @inventory_file.update_attributes(inventory_file_params)
      flash[:notice] = t('controller.successfully_updated', model: t('activerecord.models.inventory_file'))
      format.html { redirect_to(@inventory_file) }
      format.json { head :no_content }
    else
      prepare_options
      format.html { render action: "edit" }
      format.json { render json: @inventory_file.errors, status: :unprocessable_entity }
    end
  end
end