Skip to content

Commit 16db4c4

Browse files
committed
Use alert for form errors
1 parent a654a1d commit 16db4c4

File tree

11 files changed

+22
-85
lines changed

11 files changed

+22
-85
lines changed

app/controllers/problems_controller.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def edit
8585
def create
8686
params[:problem][:compiler_ids] ||= []
8787
@problem = Problem.new(check_params())
88+
@ban_compiler_ids = params[:problem][:compiler_ids].map(&:to_i).to_set
8889
respond_to do |format|
8990
if @problem.save
9091
format.html { redirect_to @problem, notice: 'Problem was successfully created.' }
@@ -98,6 +99,7 @@ def create
9899

99100
def update
100101
params[:problem][:compiler_ids] ||= []
102+
@ban_compiler_ids = params[:problem][:compiler_ids].map(&:to_i).to_set
101103
respond_to do |format|
102104
@problem.attributes = check_params()
103105
pre_ids = @problem.testdata_sets.collect(&:id)

app/views/articles/_form.html.erb

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,7 @@
55
<% end %>
66

77
<%= nested_form_for(@article) do |f| %>
8-
<% if @article.errors.any? %>
9-
<div id="error_explanation">
10-
<h2><%= pluralize(@article.errors.count, "error") %> prohibited this article from being saved:</h2>
11-
<ul>
12-
<% @article.errors.full_messages.each do |msg| %>
13-
<li><%= msg %></li>
14-
<% end %>
15-
</ul>
16-
</div>
17-
<% end %>
8+
<%= render partial: "shared/errors", locals: {errors: @article.errors, item: 'article'} %>
189

1910
<div class="form-group">
2011
<%= f.label :pinned, "Pin to top" %><br>

app/views/comments/_form.html.erb

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,7 @@
33
<% form_target = [@contest] + form_target %>
44
<% end %>
55
<%= form_for form_target do |f| %>
6-
<% if @post.errors.any? %>
7-
<div id="error_explanation">
8-
<h4><%= pluralize(@post.errors.count, "error") %> prohibited this problem from being saved:</h4>
9-
<ul>
10-
<% @post.errors.full_messages.each do |msg| %>
11-
<li><%= msg %></li>
12-
<% end %>
13-
</ul>
14-
</div>
15-
<% end %>
6+
<%= render partial: "shared/errors", locals: {errors: @comment.errors, item: 'comment'} %>
167

178
<div class="form-group">
189
<%= f.label :title, "Title:" %><br />

app/views/contests/_form.html.erb

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,7 @@
55
<% end %>
66

77
<%= nested_form_for(@contest) do |f| %>
8-
<% if @contest.errors.any? %>
9-
<div id="error_explanation">
10-
<h2><%= pluralize(@contest.errors.count, "error") %> prohibited this contest from being saved:</h2>
11-
12-
<ul>
13-
<% @contest.errors.full_messages.each do |msg| %>
14-
<li><%= msg %></li>
15-
<% end %>
16-
</ul>
17-
</div>
18-
<% end %>
8+
<%= render partial: "shared/errors", locals: {errors: @contest.errors, item: 'contest'} %>
199

2010
<div class="form-group">
2111
<%= f.label :title %>
Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
<%= form_for @judge_server do |f| %>
2-
<% if @judge_server.errors.any? %>
3-
<div id="error_explanation">
4-
<h2><%= pluralize(@judge_server.errors.count, "error") %> prohibited this JudgeServer from being saved:</h2>
2+
<%= render partial: "shared/errors", locals: {errors: @judge_server.errors, item: 'JudgeServer'} %>
53

6-
<ul>
7-
<% @judge_server.errors.full_messages.each do |msg| %>
8-
<li><%= msg %></li>
9-
<% end %>
10-
</ul>
11-
</div>
12-
<% end %>
134
<div class="form-group">
145
<%= f.label :name, 'Server Name' %> <br>
156
<%= f.text_field :name, :class => 'form-control', :placeholder => 'Server Name' %>
@@ -25,6 +16,4 @@
2516
<div class="form-group">
2617
<%= f.submit :class=>"btn btn-primary "%>
2718
</div>
28-
29-
3019
<% end %>

app/views/posts/_form.html.erb

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,7 @@
88

99
<% form_target = @postable ? [@postable, @post] : @post %>
1010
<%= form_for form_target do |f| %>
11-
<% if @post.errors.any? %>
12-
<div id="error_explanation">
13-
<h4><%= pluralize(@post.errors.count, "error") %> prohibited this problem from being saved:</h4>
14-
<ul>
15-
<% @post.errors.full_messages.each do |msg| %>
16-
<li><%= msg %></li>
17-
<% end %>
18-
</ul>
19-
</div>
20-
<% end %>
11+
<%= render partial: "shared/errors", locals: {errors: @post.errors, item: 'post'} %>
2112

2213
<div class="form-group">
2314
<%= f.label :title, "Title:" %> <br />

app/views/problems/_form.html.erb

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,7 @@
55
<% end %>
66

77
<%= nested_form_for @problem, :html => {:class => 'form', :id => 'problem-form'} do |f| %>
8-
<% if @problem.errors.any? %>
9-
<div id="error_explanation">
10-
<h2><%= pluralize(@problem.errors.count, "error") %> prohibited this problem from being saved:</h2>
11-
<ul>
12-
<% @problem.errors.full_messages.each do |msg| %>
13-
<li><%= msg %></li>
14-
<% end %>
15-
</ul>
16-
</div>
17-
<% end %>
8+
<%= render partial: "shared/errors", locals: {errors: @problem.errors, item: 'problem'} %>
189

1910
<div class="row">
2011
<div class="col-md-12">

app/views/shared/_errors.html.erb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<% if errors.any? %>
2+
<div id="error_explanation" class="alert alert-danger" role="alert">
3+
<strong><%= pluralize(errors.count, "error") %> prohibited this <%= item %> from being saved:</strong>
4+
<ul>
5+
<% errors.full_messages.each do |msg| %>
6+
<li><%= msg %></li>
7+
<% end %>
8+
</ul>
9+
</div>
10+
<% end %>

app/views/submissions/_form.html.erb

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,7 @@
44
<% set_page_title "New Submission - " + @problem.id.to_s + " - " + @problem.name %>
55
<% end %>
66
<%= form_for [@problem, @submission] do |f| %>
7-
<% if @submission.errors.any? %>
8-
<div id="error_explanation">
9-
<h2><%= pluralize(@submission.errors.count, "error") %> prohibited this submission from being saved:</h2>
10-
<ul>
11-
<% @submission.errors.full_messages.each do |msg| %>
12-
<li><%= msg %></li>
13-
<% end %>
14-
</ul>
15-
</div>
16-
<% end %>
7+
<%= render partial: "shared/errors", locals: {errors: @submission.errors, item: 'submission'} %>
178

189
<div class="form-group">
1910
<%= render 'compiler_chooser', :f => f %>

app/views/testdata/_form.html.erb

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
<%= form_for [@problem, @testdatum], :html => {:multipart => true} do |f| %>
2-
<% if @testdatum.errors.any? %>
3-
<div id="error_explanation">
4-
<h2><%= pluralize(@testdatum.errors.count, "error") %> prohibited this testdatum from being saved:</h2>
5-
<ul>
6-
<% @testdatum.errors.full_messages.each do |msg| %>
7-
<li><%= msg %></li>
8-
<% end %>
9-
</ul>
10-
</div>
11-
<% end %>
2+
<%= render partial: "shared/errors", locals: {errors: @testdatum.errors, item: 'testdatum'} %>
123

134
<div class="form-group">
145
<%= f.label :test_input, "input testdata" %><br>

0 commit comments

Comments
 (0)