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
@@ -80,26 +80,48 | |||||
|
80 | @description = Description.new(params[:description]) |
|
80 | @description = Description.new(params[:description]) |
|
81 | if !@description.save |
|
81 | if !@description.save |
|
82 | flash[:notice] = 'Error saving description' |
|
82 | flash[:notice] = 'Error saving description' |
|
83 | render :action => 'edit' and return |
|
83 | render :action => 'edit' and return |
|
84 | end |
|
84 | end |
|
85 | @problem.description = @description |
|
85 | @problem.description = @description |
|
86 | elsif @description!=nil |
|
86 | elsif @description!=nil |
|
87 | if !@description.update_attributes(params[:description]) |
|
87 | if !@description.update_attributes(params[:description]) |
|
88 | flash[:notice] = 'Error saving description' |
|
88 | flash[:notice] = 'Error saving description' |
|
89 | render :action => 'edit' and return |
|
89 | render :action => 'edit' and return |
|
90 | end |
|
90 | end |
|
91 | end |
|
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 | if @problem.update_attributes(params[:problem]) |
|
96 | if @problem.update_attributes(params[:problem]) |
|
93 | flash[:notice] = 'Problem was successfully updated.' |
|
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 | redirect_to :action => 'show', :id => @problem |
|
116 | redirect_to :action => 'show', :id => @problem |
|
95 | else |
|
117 | else |
|
96 | render :action => 'edit' |
|
118 | render :action => 'edit' |
|
97 | end |
|
119 | end |
|
98 | end |
|
120 | end |
|
99 |
|
121 | ||
|
100 | def destroy |
|
122 | def destroy |
|
101 | Problem.find(params[:id]).destroy |
|
123 | Problem.find(params[:id]).destroy |
|
102 | redirect_to :action => 'list' |
|
124 | redirect_to :action => 'list' |
|
103 | end |
|
125 | end |
|
104 |
|
126 | ||
|
105 | def toggle |
|
127 | def toggle |
@@ -39,14 +39,16 | |||||
|
39 | <%= text_area :description, :body, :rows => 10, :cols => 80 %></p> |
|
39 | <%= text_area :description, :body, :rows => 10, :cols => 80 %></p> |
|
40 |
|
40 | ||
|
41 | <p><label for="description_markdowned">Markdowned?</label> |
|
41 | <p><label for="description_markdowned">Markdowned?</label> |
|
42 | <%= select "description", |
|
42 | <%= select "description", |
|
43 | "markdowned", |
|
43 | "markdowned", |
|
44 | [['True',true],['False',false]], |
|
44 | [['True',true],['False',false]], |
|
45 | {:selected => (@description) ? @description.markdowned : false } |
|
45 | {:selected => (@description) ? @description.markdowned : false } |
|
46 | %></p> |
|
46 | %></p> |
|
47 |
|
47 | ||
|
48 | <p><label for="problem_url">URL</label><br/> |
|
48 | <p><label for="problem_url">URL</label><br/> |
|
49 | <%= text_field 'problem', 'url' %></p> |
|
49 | <%= text_field 'problem', 'url' %></p> |
|
50 |
|
50 | ||
|
|
51 | + <p>Task PDF <%= file_field_tag 'file' %></p> | ||
|
|
52 | + | ||
|
51 |
|
53 | ||
|
52 | <!--[eoform:problem]--> |
|
54 | <!--[eoform:problem]--> |
@@ -1,9 +1,9 | |||||
|
1 | <h1>Editing problem</h1> |
|
1 | <h1>Editing problem</h1> |
|
2 |
|
2 | ||
|
3 |
- <%= form_tag |
|
3 | + <%= form_tag({action: 'update', id: @problem},multipart: true) do %> |
|
4 | <%= render :partial => 'form' %> |
|
4 | <%= render :partial => 'form' %> |
|
5 | <%= submit_tag 'Edit' %> |
|
5 | <%= submit_tag 'Edit' %> |
|
6 | <% end %> |
|
6 | <% end %> |
|
7 |
|
7 | ||
|
8 | <%= link_to 'Show', :action => 'show', :id => @problem %> | |
|
8 | <%= link_to 'Show', :action => 'show', :id => @problem %> | |
|
9 | <%= link_to 'Back', :action => 'list' %> |
|
9 | <%= link_to 'Back', :action => 'list' %> |
You need to be logged in to leave comments.
Login now