Fixes updating contests

This commit is contained in:
Luke Barratt 2014-05-19 20:51:32 +01:00
parent f41e6e0d5a
commit 028fe33941
3 changed files with 12 additions and 3 deletions

View file

@ -66,17 +66,17 @@ class ContestsController < ApplicationController
def update
raise AccessError unless @contest.can_update? cuser
if params[:commit] == "Save"
if update_type == "contest"
if @contest.update_attributes(params[:contest])
flash[:notice] = t(:contests_update)
redirect_to @contest
else
render :edit
end
elsif params[:commit] == "Add map"
elsif update_type == "map"
@contest.maps << Map.find(params[:map])
render :edit
elsif params[:commit] == "Add team"
elsif update_type == "team"
contester = Contester.new
contester.team = Team.find params[:team]
contester.contest = @contest
@ -107,4 +107,8 @@ class ContestsController < ApplicationController
def get_contest
@contest = Contest.find params[:id]
end
def update_type
params[:type]
end
end

View file

@ -16,6 +16,7 @@
<div class="tab" id="general">
<%= form_for @contest, html: { class: 'square' } do |f| %>
<%= render 'shared/errors', messages: @contest.errors.full_messages %>
<%= hidden_field_tag :type, 'contest' %>
<div class="fields horizontal">
<%= f.label :name %>
@ -106,6 +107,7 @@
<%= form_for @contest.brackets.build, html: { class: 'square' } do |f| %>
<%= render 'shared/errors', messages: @contest.brackets.last.errors.full_messages %>
<%= hidden_field_tag :type, 'contest' %>
<%= f.hidden_field :contest_id %>
@ -142,6 +144,7 @@
<%= form_for @contest do |f| %>
<%= render 'shared/errors', messages: @contest.errors.full_messages %>
<%= hidden_field_tag :type, 'map' %>
<div class="fields">
<%= select_tag :map, options_from_collection_for_select(Map.basic, :id, :name) %>
@ -184,6 +187,7 @@
<%= form_for @contest.contesters.build do |f| %>
<%= render 'shared/errors', messages: @contest.contesters.last.errors.full_messages %>
<%= hidden_field_tag :type, 'team' %>
<%= f.hidden_field :contest_id %>

View file

@ -3,6 +3,7 @@ en:
articles_article_views: "Views"
bans_create: "Ban was successfully created."
bans_update: "Ban was successfully updated."
brackets_create: "Bracket was successfully created."
brackets_update: "Bracket was successfully updated."
articles_create: "Article was successfully created."
articles_update: "Article was successfully updated."