Description:
- fix pdf loading fail
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r634:56cf4357ce2a - - 4 files changed: 11 inserted, 4 deleted

@@ -79,25 +79,25
79 end
79 end
80 @problem.description = @description
80 @problem.description = @description
81 elsif @description
81 elsif @description
82 if !@description.update_attributes(params[:description])
82 if !@description.update_attributes(params[:description])
83 flash[:notice] = 'Error saving description'
83 flash[:notice] = 'Error saving description'
84 render :action => 'edit' and return
84 render :action => 'edit' and return
85 end
85 end
86 end
86 end
87 if params[:file] and params[:file].content_type != 'application/pdf'
87 if params[:file] and params[:file].content_type != 'application/pdf'
88 flash[:notice] = 'Error: Uploaded file is not PDF'
88 flash[:notice] = 'Error: Uploaded file is not PDF'
89 render :action => 'edit' and return
89 render :action => 'edit' and return
90 end
90 end
91 - if @problem.update_attributes(params[:problem])
91 + if @problem.update_attributes(problem_params)
92 flash[:notice] = 'Problem was successfully updated.'
92 flash[:notice] = 'Problem was successfully updated.'
93 unless params[:file] == nil or params[:file] == ''
93 unless params[:file] == nil or params[:file] == ''
94 flash[:notice] = 'Problem was successfully updated and a new PDF file is uploaded.'
94 flash[:notice] = 'Problem was successfully updated and a new PDF file is uploaded.'
95 out_dirname = "#{Problem.download_file_basedir}/#{@problem.id}"
95 out_dirname = "#{Problem.download_file_basedir}/#{@problem.id}"
96 if not FileTest.exists? out_dirname
96 if not FileTest.exists? out_dirname
97 Dir.mkdir out_dirname
97 Dir.mkdir out_dirname
98 end
98 end
99
99
100 out_filename = "#{out_dirname}/#{@problem.name}.pdf"
100 out_filename = "#{out_dirname}/#{@problem.name}.pdf"
101 if FileTest.exists? out_filename
101 if FileTest.exists? out_filename
102 File.delete out_filename
102 File.delete out_filename
103 end
103 end
@@ -276,13 +276,19
276 params.keys.each do |k|
276 params.keys.each do |k|
277 if k.index('prob-')==0
277 if k.index('prob-')==0
278 name, id, order = k.split('-')
278 name, id, order = k.split('-')
279 problems << Problem.find(id)
279 problems << Problem.find(id)
280 end
280 end
281 end
281 end
282 problems
282 problems
283 end
283 end
284
284
285 def get_problems_stat
285 def get_problems_stat
286 end
286 end
287
287
288 + private
289 +
290 + def problem_params
291 + params.require(:problem).permit(:name, :full_name, :full_score, :date_added, :available, :test_allowed,:output_only, :url, :description)
292 + end
293 +
288 end
294 end
@@ -109,25 +109,25
109 :remark => remark})
109 :remark => remark})
110 end
110 end
111 user.activated = true
111 user.activated = true
112 user.save
112 user.save
113
113
114 if added_random_password
114 if added_random_password
115 note << "'#{login}' (+)"
115 note << "'#{login}' (+)"
116 else
116 else
117 note << login
117 note << login
118 end
118 end
119 end
119 end
120 end
120 end
121 - flash[:notice] = 'User(s) ' + note.join(', ') +
121 + flash[:success] = 'User(s) ' + note.join(', ') +
122 ' were successfully created. ' +
122 ' were successfully created. ' +
123 '( (+) - created with random passwords.)'
123 '( (+) - created with random passwords.)'
124 redirect_to :action => 'index'
124 redirect_to :action => 'index'
125 end
125 end
126
126
127 def edit
127 def edit
128 @user = User.find(params[:id])
128 @user = User.find(params[:id])
129 end
129 end
130
130
131 def update
131 def update
132 @user = User.find(params[:id])
132 @user = User.find(params[:id])
133 if @user.update_attributes(user_params)
133 if @user.update_attributes(user_params)
@@ -1,17 +1,18
1 <%= error_messages_for 'problem' %>
1 <%= error_messages_for 'problem' %>
2
2
3 <!--[form:problem]-->
3 <!--[form:problem]-->
4 <p><label for="problem_name">Name</label><br/>
4 <p><label for="problem_name">Name</label><br/>
5 - <%= text_field 'problem', 'name' %></p>
5 + <%= text_field 'problem', 'name' %> Do not directly edit the problem name, unless you know what you are doing. If you want to change the name, use the name change button in the problem management menu instead.
6 + </p>
6
7
7 <p><label for="problem_full_name">Full name</label><br/>
8 <p><label for="problem_full_name">Full name</label><br/>
8 <%= text_field 'problem', 'full_name' %></p>
9 <%= text_field 'problem', 'full_name' %></p>
9
10
10 <p><label for="problem_full_score">Full score</label><br/>
11 <p><label for="problem_full_score">Full score</label><br/>
11 <%= text_field 'problem', 'full_score' %></p>
12 <%= text_field 'problem', 'full_score' %></p>
12
13
13 <p><label for="problem_date_added">Date added</label><br/>
14 <p><label for="problem_date_added">Date added</label><br/>
14 <%= date_select 'problem', 'date_added' %></p>
15 <%= date_select 'problem', 'date_added' %></p>
15
16
16 <%
17 <%
17 # TODO: these should be put in model Problem, but I can't think of
18 # TODO: these should be put in model Problem, but I can't think of
@@ -12,13 +12,13
12 <%= markdown(@problem.description.body) %>
12 <%= markdown(@problem.description.body) %>
13 <% else %>
13 <% else %>
14 <pre>
14 <pre>
15 <%= @problem.description.body %>
15 <%= @problem.description.body %>
16 </pre>
16 </pre>
17 <% end %>
17 <% end %>
18 <% else %>
18 <% else %>
19 (not available)
19 (not available)
20 <% end %>
20 <% end %>
21 </p>
21 </p>
22
22
23 <%= link_to 'Edit', :action => 'edit', :id => @problem %> |
23 <%= link_to 'Edit', :action => 'edit', :id => @problem %> |
24 - <%= link_to 'Back', :action => 'list' %>
24 + <%= link_to 'Back', problems_path %>
You need to be logged in to leave comments. Login now