Class: Pageflow::Editor::FilesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/pageflow/editor/files_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/pageflow/editor/files_controller.rb', line 17

def create
  entry = DraftEntry.find(params[:entry_id])
  authorize!(:edit, entry.to_model)
  verify_edit_lock!(entry)

  @file = entry.create_file(file_type.model, create_params)
  @file.publish!

  respond_with(:editor, @file)
end

#destroyObject



67
68
69
70
71
72
73
74
75
76
# File 'app/controllers/pageflow/editor/files_controller.rb', line 67

def destroy
  entry = DraftEntry.find(params[:entry_id])
  file = entry.find_file(file_type.model, params[:id])

  authorize!(:edit, entry.to_model)
  verify_edit_lock!(entry)
  entry.remove_file(file)

  head(:no_content)
end

#indexObject



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

def index
  entry = DraftEntry.find(params[:entry_id])

  authorize!(:use_files, entry.to_model)
  @files = entry.find_files(file_type.model)

  respond_with(:editor, @files)
end

#retryObject



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/pageflow/editor/files_controller.rb', line 43

def retry
  entry = DraftEntry.find(params[:entry_id])
  file = entry.find_file(file_type.model, params[:id])

  authorize!(:retry, file.to_model)
  file.retry!

  respond_with(:editor,
               file,
               location: editor_entry_file_url(file,
                                               entry,
                                               collection_name: params[:collection_name]))
end

#reuseObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/pageflow/editor/files_controller.rb', line 28

def reuse
  entry = DraftEntry.find(params[:entry_id])
  other_entry = DraftEntry.find(file_reuse_params[:other_entry_id])

  file_reuse = FileReuse.new(entry, other_entry, file_type, file_reuse_params[:file_id])

  authorize!(:edit, entry.to_model)
  authorize!(:use, file_reuse.file.to_model)
  verify_edit_lock!(entry)

  file_reuse.save!

  redirect_to(entry_url(entry))
end

#updateObject



57
58
59
60
61
62
63
64
65
# File 'app/controllers/pageflow/editor/files_controller.rb', line 57

def update
  entry = DraftEntry.find(params[:entry_id])
  file = entry.find_file(file_type.model, params[:id])

  authorize!(:update, file.to_model)
  file.update_attributes!(update_params)

  head(:no_content)
end