Class: Dunlop::SourceFilesController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#store_or_reset_params_q

Instance Method Details

#createObject



24
25
26
27
28
29
30
31
32
# File 'app/controllers/dunlop/source_files_controller.rb', line 24

def create
  @source_file = SourceFile.factory(source_file_params)
  redirect_to source_files_path, alert: "No file given" and return unless params[:source_file][:original_file].present?
  redirect_to source_files_path, alert: "No type specified" and return unless params[:source_file][:sti_type].present?
  authorize! :manage, @source_file
  @source_file.user = current_user
  @source_file.save && @source_file.autoload!
  redirect_to source_files_path
end

#destroyObject



34
35
36
37
38
39
# File 'app/controllers/dunlop/source_files_controller.rb', line 34

def destroy
  @source_file = SourceFile.find(params[:id])
  authorize! :manage, @source_file
  @source_file.destroy
  redirect_to source_files_path
end

#downloadObject



41
42
43
44
45
46
# File 'app/controllers/dunlop/source_files_controller.rb', line 41

def download
  @source_file = SourceFile.find(params[:id])
  authorize! :download, @source_file
  return redirect_to :back, alert: "File is no longer present" unless @source_file.original_file.present?
  send_file @source_file.original_file.current_path
end

#indexObject



4
5
6
7
8
9
10
# File 'app/controllers/dunlop/source_files_controller.rb', line 4

def index
  authorize! :index, SourceFile
  @q = SourceFile.where(sti_type: SourceFile.classes.select{|cls| can? :read, cls}.map(&:name)).search(params[:q])
  @q.sorts = "created_at desc" if @q.sorts.empty?
  @source_files = @q.result.page(params[:page]).per(100)
  respond_with(@source_files)
end

#newObject



18
19
20
21
22
# File 'app/controllers/dunlop/source_files_controller.rb', line 18

def new
  @source_file = SourceFile.new
  authorize! :manage, @source_file
  respond_with(@source_file)
end

#scheduleObject



48
49
50
51
52
53
54
# File 'app/controllers/dunlop/source_files_controller.rb', line 48

def schedule
  @source_file = SourceFile.find(params[:id])
  authorize! :manage, @source_file
  @source_file.scheduled!
  flash[:notice] = "Successfully scheduled loading of source file"
  redirect_to source_files_path
end

#showObject



12
13
14
15
16
# File 'app/controllers/dunlop/source_files_controller.rb', line 12

def show
  @source_file = SourceFile.find(params[:id])
  authorize! :read, @source_file
  respond_with(@source_file)
end