-
Notifications
You must be signed in to change notification settings - Fork 65
/
tailoring_files_controller.rb
60 lines (49 loc) · 1.55 KB
/
tailoring_files_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
class TailoringFilesController < ApplicationController
include Foreman::Controller::AutoCompleteSearch
include Foreman::Controller::Parameters::TailoringFile
before_filter :find_tailoring_file, :only => [:destroy, :update, :edit]
before_filter :handle_file_upload, :only => [:create, :update]
def model_of_controller
::ForemanOpenscap::TailoringFile
end
def index
@tailoring_files = resource_base.search_for(params[:search], :order => params[:order])
.paginate(:page => params[:page], :per_page => params[:per_page])
end
def new
@tailoring_file = ::ForemanOpenscap::TailoringFile.new
end
def create
@tailoring_file = ForemanOpenscap::TailoringFile.new(tailoring_file_params)
if @tailoring_file.save
process_success
else
process_error
end
end
def edit
end
def update
if @tailoring_file.update_attributes(tailoring_file_params)
process_success
else
process_error
end
end
def destroy
if @tailoring_file.destroy
process_success
else
process_error :object => @tailoring_file
end
end
private
def find_tailoring_file
@tailoring_file = resource_base.find(params[:id])
end
def handle_file_upload
return unless params[:tailoring_file] && raw_file = params[:tailoring_file][:scap_file]
params[:tailoring_file][:original_filename] = raw_file.original_filename
params[:tailoring_file][:scap_file] = raw_file.tempfile.read if raw_file.respond_to?(:tempfile) && raw_file.tempfile.respond_to?(:read)
end
end