summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authortkimia <tkimia@purdue.edu>2014-04-06 22:16:05 -0400
committertkimia <tkimia@purdue.edu>2014-04-06 22:16:05 -0400
commit546b5895e7fe48d7f2e3c1032622805ee8fba090 (patch)
tree40293728151a1347d33dcda7a0ecd917904af8ba /app
parent5084f01e0ea7ba7c378982099fdbf9880857f091 (diff)
matches start
Diffstat (limited to 'app')
-rw-r--r--app/controllers/matches_controller.rb25
-rw-r--r--app/views/matches/index.html.erb10
2 files changed, 33 insertions, 2 deletions
diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb
index e9fe727..ee68e11 100644
--- a/app/controllers/matches_controller.rb
+++ b/app/controllers/matches_controller.rb
@@ -1,5 +1,5 @@
class MatchesController < ApplicationController
- before_action :set_tournament, only: [:index]
+ before_action :set_tournament, only: [:index, :update]
# GET /matches
# GET /matches.json
@@ -150,6 +150,29 @@ class MatchesController < ApplicationController
end
+ def update
+ case params[:update_action]
+ when "start"
+ check_permission(:edit, @tournament)
+ status = 1
+ respond_to do |format|
+ if @match
+ format.html { redirect_to tournament_match_path(@tournament, self), notice: 'Match has started.' }
+ format.json { head :no_content }
+ else
+ format.html { redirect_to @tournament, notice: "You don't have permission to start this match." }
+ format.json { render json: "Permission denied", status: :forbidden }
+ end
+ end
+ else
+ respond_to do |format|
+ format.html { redirect_to @tournament, notice: "Invalid action", status: :unprocessable_entity }
+ format.json { render json: @tournament.errors, status: :unprocessable_entity }
+ end
+ end
+
+ end
+
private
# Use callbacks to share common setup or constraints between actions.
def set_match
diff --git a/app/views/matches/index.html.erb b/app/views/matches/index.html.erb
index 6fd831f..052d176 100644
--- a/app/views/matches/index.html.erb
+++ b/app/views/matches/index.html.erb
@@ -18,7 +18,15 @@
<td><%= match.id%></td>
<td><%= match.name %></td>
<td><%= link_to "Show", tournament_match_path(@tournament, match) %>
- <td><%= submit_tag("Start Match") %>
+ <td> <%# If user is the host, let them start the tournment %>
+ <% if @tournament.hosts.include?(current_user) %>
+
+ <%= form_tag(tournament_match_path(@tournament, match), method: "put") do %>
+ <input type="hidden" name="update_action" value="start">
+ <%= submit_tag("Start Match") %>
+ <% end %>
+ <% end %>
+</div></td>
</tr>
<% end %>
</tbody>