Description:
add option to update PDF file of a problem in /problem/edit/:id
(grafted from 15b2554bf365f8639b5e94db4f1d9a277007808a)
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r364:9bd14bb6e95d - - 3 files changed: 25 inserted, 1 deleted
@@ -89,8 +89,30 | |||
|
89 | 89 | render :action => 'edit' and return |
|
90 | 90 | end |
|
91 | 91 | end |
|
92 | + if params[:file] and params[:file].content_type != 'application/pdf' | |
|
93 | + flash[:notice] = 'Error: Uploaded file is not PDF' | |
|
94 | + render :action => 'edit' and return | |
|
95 | + end | |
|
92 | 96 | if @problem.update_attributes(params[:problem]) |
|
93 | 97 | flash[:notice] = 'Problem was successfully updated.' |
|
98 | + unless params[:file] == nil or params[:file] == '' | |
|
99 | + flash[:notice] = 'Problem was successfully updated and a new PDF file is uploaded.' | |
|
100 | + out_dirname = "#{Problem.download_file_basedir}/#{@problem.id}" | |
|
101 | + if not FileTest.exists? out_dirname | |
|
102 | + Dir.mkdir out_dirname | |
|
103 | + end | |
|
104 | + | |
|
105 | + out_filename = "#{out_dirname}/#{@problem.name}.pdf" | |
|
106 | + if FileTest.exists? out_filename | |
|
107 | + File.delete out_filename | |
|
108 | + end | |
|
109 | + | |
|
110 | + File.open(out_filename,"wb") do |file| | |
|
111 | + file.write(params[:file].read) | |
|
112 | + end | |
|
113 | + @problem.description_filename = "#{@problem.name}.pdf" | |
|
114 | + @problem.save | |
|
115 | + end | |
|
94 | 116 | redirect_to :action => 'show', :id => @problem |
|
95 | 117 | else |
|
96 | 118 | render :action => 'edit' |
You need to be logged in to leave comments.
Login now