Class: EziiOsFilesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/ezii_os_files_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /ezii_os_files POST /ezii_os_files.json



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/controllers/ezii_os_files_controller.rb', line 57

def create
  @ezii_os_file = EziiOsFile.new(ezii_os_file_params)

  respond_to do |format|
    if @ezii_os_file.save
      format.html { redirect_to @ezii_os_file, notice: 'Ezii os file was successfully created.' }
      format.json { render :show, status: :created, location: @ezii_os_file }
    else
      format.html { render :new }
      format.json { render json: @ezii_os_file.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /ezii_os_files/1 DELETE /ezii_os_files/1.json



87
88
89
90
91
92
93
# File 'app/controllers/ezii_os_files_controller.rb', line 87

def destroy
  @ezii_os_file.destroy
  respond_to do |format|
    format.html { redirect_to ezii_os_files_url, notice: 'Ezii os file was successfully destroyed.' }
    format.json { head :no_content }
  end
end

#editObject

GET /ezii_os_files/1/edit



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

def edit
end

#indexObject

GET /ezii_os_files GET /ezii_os_files.json



16
17
18
# File 'app/controllers/ezii_os_files_controller.rb', line 16

def index
  @ezii_os_files = EziiOsFile.all
end

#newObject

GET /ezii_os_files/new



47
48
49
# File 'app/controllers/ezii_os_files_controller.rb', line 47

def new
  @ezii_os_file = EziiOsFile.new
end

#showObject

GET /ezii_os_files/1 GET /ezii_os_files/1.json



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/ezii_os_files_controller.rb', line 22

def show
  @path = EziiOsPath.new(params[:id])

  case @path.file_system.machine_readable_identifier
  when 'local'
    relative_path_to_file = params[:id].match(/\/public\/(.*)\Z/)[1]
    @path.https_url = '/' + relative_path_to_file.gsub(/\s/, '%20')
  when 'dropbox'
    bda = BanalDropboxApi.new
    bda.download(@path.file_system_path) do |file_content|
      @last_file_input = file_content
      
      t = Tempfile.new(['file', File.extname(@path.file_system_path)])
      
      t.binmode
      t.write(file_content)

      @path.local_file_system_path = t.path
    end

    @path.https_url = bda.get_link(@path.file_system_path) rescue nil
  end
end

#updateObject

PATCH/PUT /ezii_os_files/1 PATCH/PUT /ezii_os_files/1.json



73
74
75
76
77
78
79
80
81
82
83
# File 'app/controllers/ezii_os_files_controller.rb', line 73

def update
  respond_to do |format|
    if @ezii_os_file.update(ezii_os_file_params)
      format.html { redirect_to @ezii_os_file, notice: 'Ezii os file was successfully updated.' }
      format.json { render :show, status: :ok, location: @ezii_os_file }
    else
      format.html { render :edit }
      format.json { render json: @ezii_os_file.errors, status: :unprocessable_entity }
    end
  end
end