Description:
fix problem edit page
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r590:0ef720704122 - - 2 files changed: 4 inserted, 4 deleted
@@ -1,42 +1,42 | |||||
|
1 | class ProblemsController < ApplicationController |
|
1 | class ProblemsController < ApplicationController |
|
2 |
|
2 | ||
|
3 | before_filter :authenticate, :authorization |
|
3 | before_filter :authenticate, :authorization |
|
4 |
|
4 | ||
|
5 | in_place_edit_for :problem, :name |
|
5 | in_place_edit_for :problem, :name |
|
6 | in_place_edit_for :problem, :full_name |
|
6 | in_place_edit_for :problem, :full_name |
|
7 | in_place_edit_for :problem, :full_score |
|
7 | in_place_edit_for :problem, :full_score |
|
8 |
|
8 | ||
|
9 | def index |
|
9 | def index |
|
10 | @problems = Problem.find(:all, :order => 'date_added DESC') |
|
10 | @problems = Problem.find(:all, :order => 'date_added DESC') |
|
11 | end |
|
11 | end |
|
12 |
|
12 | ||
|
13 | # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) |
|
13 | # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) |
|
14 | verify :method => :post, :only => [ :destroy, |
|
14 | verify :method => :post, :only => [ :destroy, |
|
15 | :create, :quick_create, |
|
15 | :create, :quick_create, |
|
16 | :do_manage, |
|
16 | :do_manage, |
|
17 | :do_import, |
|
17 | :do_import, |
|
18 |
- |
|
18 | + ], |
|
19 | :redirect_to => { :action => :index } |
|
19 | :redirect_to => { :action => :index } |
|
20 |
|
20 | ||
|
21 | def show |
|
21 | def show |
|
22 | @problem = Problem.find(params[:id]) |
|
22 | @problem = Problem.find(params[:id]) |
|
23 | end |
|
23 | end |
|
24 |
|
24 | ||
|
25 | def new |
|
25 | def new |
|
26 | @problem = Problem.new |
|
26 | @problem = Problem.new |
|
27 | @description = nil |
|
27 | @description = nil |
|
28 | end |
|
28 | end |
|
29 |
|
29 | ||
|
30 | def create |
|
30 | def create |
|
31 | @problem = Problem.new(params[:problem]) |
|
31 | @problem = Problem.new(params[:problem]) |
|
32 | @description = Description.new(params[:description]) |
|
32 | @description = Description.new(params[:description]) |
|
33 | if @description.body!='' |
|
33 | if @description.body!='' |
|
34 | if !@description.save |
|
34 | if !@description.save |
|
35 | render :action => new and return |
|
35 | render :action => new and return |
|
36 | end |
|
36 | end |
|
37 | else |
|
37 | else |
|
38 | @description = nil |
|
38 | @description = nil |
|
39 | end |
|
39 | end |
|
40 | @problem.description = @description |
|
40 | @problem.description = @description |
|
41 | if @problem.save |
|
41 | if @problem.save |
|
42 | flash[:notice] = 'Problem was successfully created.' |
|
42 | flash[:notice] = 'Problem was successfully created.' |
@@ -50,56 +50,56 | |||||
|
50 | @problem = Problem.new(params[:problem]) |
|
50 | @problem = Problem.new(params[:problem]) |
|
51 | @problem.full_name = @problem.name if @problem.full_name == '' |
|
51 | @problem.full_name = @problem.name if @problem.full_name == '' |
|
52 | @problem.full_score = 100 |
|
52 | @problem.full_score = 100 |
|
53 | @problem.available = false |
|
53 | @problem.available = false |
|
54 | @problem.test_allowed = true |
|
54 | @problem.test_allowed = true |
|
55 | @problem.output_only = false |
|
55 | @problem.output_only = false |
|
56 | @problem.date_added = Time.new |
|
56 | @problem.date_added = Time.new |
|
57 | if @problem.save |
|
57 | if @problem.save |
|
58 | flash[:notice] = 'Problem was successfully created.' |
|
58 | flash[:notice] = 'Problem was successfully created.' |
|
59 | redirect_to action: :index |
|
59 | redirect_to action: :index |
|
60 | else |
|
60 | else |
|
61 | flash[:notice] = 'Error saving problem' |
|
61 | flash[:notice] = 'Error saving problem' |
|
62 | redirect_to action: :index |
|
62 | redirect_to action: :index |
|
63 | end |
|
63 | end |
|
64 | end |
|
64 | end |
|
65 |
|
65 | ||
|
66 | def edit |
|
66 | def edit |
|
67 | @problem = Problem.find(params[:id]) |
|
67 | @problem = Problem.find(params[:id]) |
|
68 | @description = @problem.description |
|
68 | @description = @problem.description |
|
69 | end |
|
69 | end |
|
70 |
|
70 | ||
|
71 | def update |
|
71 | def update |
|
72 | @problem = Problem.find(params[:id]) |
|
72 | @problem = Problem.find(params[:id]) |
|
73 | @description = @problem.description |
|
73 | @description = @problem.description |
|
74 |
- if @description |
|
74 | + if @description.nil? and params[:description][:body]!='' |
|
75 | @description = Description.new(params[:description]) |
|
75 | @description = Description.new(params[:description]) |
|
76 | if !@description.save |
|
76 | if !@description.save |
|
77 | flash[:notice] = 'Error saving description' |
|
77 | flash[:notice] = 'Error saving description' |
|
78 | render :action => 'edit' and return |
|
78 | render :action => 'edit' and return |
|
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(params[:problem]) |
|
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 |
|
104 |
|
104 | ||
|
105 | File.open(out_filename,"wb") do |file| |
|
105 | File.open(out_filename,"wb") do |file| |
@@ -1,9 +1,9 | |||||
|
1 | <h1>Editing problem</h1> |
|
1 | <h1>Editing problem</h1> |
|
2 |
|
2 | ||
|
3 |
- <%= form_ |
|
3 | + <%= form_for @problem,url:{action: 'update'},html: {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