From c68ee2efe5aa13dadc0d3954afd6ecbb2481a2ab Mon Sep 17 00:00:00 2001 From: Prommah Date: Sun, 8 Nov 2015 09:02:13 +0000 Subject: [PATCH] Bug fixes, improved consistency & cleanliness --- app/controllers/matches_controller.rb | 28 ++++--- app/views/matches/show.html.erb | 4 +- config/routes.rb | 109 +++++++++++++------------- 3 files changed, 74 insertions(+), 67 deletions(-) mode change 100644 => 100755 app/views/matches/show.html.erb mode change 100644 => 100755 config/routes.rb diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index 8e0ea0c..2125ac3 100755 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -6,7 +6,7 @@ class MatchesController < ApplicationController end def show - @ownpred = @match.predictions.first conditions: {user_id: cuser.id} if cuser + @ownpred = @match.predictions.first conditions: { user_id: cuser.id } if cuser @newpred = @match.predictions.build end @@ -17,8 +17,9 @@ class MatchesController < ApplicationController end def admin - @matches = Match.active.includes(:contest, :contester1, :contester2, :map1, :map2, :referee).all.group_by {|t| t.week.to_s }.to_a.reverse - render :layout => "full" + @matches = Match.active.includes(:contest, :contester1, :contester2, :map1, :map2, :referee). + all.group_by { |t| t.week.to_s }.to_a.reverse + render layout: "full" end def extra @@ -39,7 +40,7 @@ class MatchesController < ApplicationController if @match.save flash[:notice] = t(:matches_create) - redirect_to controller: 'contests', action: 'edit', id: @match.contest + redirect_to edit_contest_path(@match.contest) else render :new end @@ -49,11 +50,11 @@ class MatchesController < ApplicationController raise AccessError unless @match.can_update? cuser, params[:match] if params[:match][:matchers_attributes] params[:match][:matchers_attributes].each do |key, matcher| - matcher['_destroy'] = matcher['_destroy'] == "keep" ? false : true - if matcher['user_id'] == "" + matcher["_destroy"] = matcher["_destroy"] == "keep" ? false : true + if matcher["user_id"] == "" params[:match][:matchers_attributes].delete key - elsif matcher['user_id'].to_i == 0 - matcher['user_id'] = User.find_by_username(matcher['user_id']).id + elsif matcher["user_id"].to_i == 0 + matcher["user_id"] = User.find_by_username(matcher["user_id"]).id end end end @@ -71,7 +72,12 @@ class MatchesController < ApplicationController end end else - render :edit + if URI(request.referer).path == match_ref_path(@match) + ref + render :ref + else + render :edit + end end end @@ -90,13 +96,13 @@ class MatchesController < ApplicationController @match.hltv_stop flash[:notice] = t(:hltv_stopped) end - redirect_to action: 'show' + redirect_to action: "show" end def destroy raise AccessError unless @match.can_destroy? cuser @match.destroy - redirect_to controller: 'contests', action: 'edit', id: @match.contest + redirect_to edit_contest_path(@match.contest) end private diff --git a/app/views/matches/show.html.erb b/app/views/matches/show.html.erb old mode 100644 new mode 100755 index eb99448..0a62dd4 --- a/app/views/matches/show.html.erb +++ b/app/views/matches/show.html.erb @@ -117,9 +117,9 @@ <% end %> - <% if cuser and @match.can_update? cuser, referee_id: cuser.id %> + <% if cuser and @match.can_update? cuser, [:report] %>
- <%= link_to "Referee Admin", { controller: :matches, action: 'ref', id: @match }, class: 'button' %> + <%= link_to "Referee Admin", match_ref_path(@match), class: 'button' %>
<% end %> diff --git a/config/routes.rb b/config/routes.rb old mode 100644 new mode 100755 index 1442471..80f0f11 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,6 @@ -Ensl::Application.routes.draw do +Ensl::Application.routes.draw do %w(403 404 422 500).each do |code| - get code, to: 'errors#show', code: code + get code, to: "errors#show", code: code end namespace :api do @@ -17,12 +17,12 @@ Ensl::Application.routes.draw do resources :versions end - match 'contests/del_map' - match 'contests/scores' - match 'contests/historical', to: "contests#historical" + match "contests/del_map" + match "contests/scores" + match "contests/historical", to: "contests#historical" resources :contests do - get 'current', on: :collection + get "current", on: :collection end resources :log_events @@ -30,7 +30,7 @@ Ensl::Application.routes.draw do resources :options resources :polls - match 'comments/quote' + match "comments/quote" resources :comments resources :shoutmsgs @@ -43,8 +43,8 @@ Ensl::Application.routes.draw do resources :forumers resources :topics - match 'forums/up' - match 'forums/down' + match "forums/up" + match "forums/down" resources :forums resources :users @@ -55,9 +55,10 @@ Ensl::Application.routes.draw do resources :servers resources :predictions resources :rounds - resources :matches do |m| + + get "matches/ref/:id" => "matches#ref", as: :match_ref + resources :matches do get :admin, to: "matches#admin", on: :collection - get :ref, to: "matches#ref" end resources :maps @@ -73,66 +74,66 @@ Ensl::Application.routes.draw do resources :bans resources :tweets resources :issues - - match 'posts/quote' + + match "posts/quote" resources :posts resources :brackets - match 'about/action' - match 'about/staff' - match 'about/statistics' + match "about/action" + match "about/staff" + match "about/statistics" - match 'refresh', to: "application#refresh" - match 'search', to: "application#search" + match "refresh", to: "application#refresh" + match "search", to: "application#search" - match 'news', to: "articles#news_index" - match 'news/archive', to: "articles#news_archive" - match 'news/admin', to: "articles#admin" - match 'articles/cleanup' + match "news", to: "articles#news_index" + match "news/archive", to: "articles#news_archive" + match "news/admin", to: "articles#admin" + match "articles/cleanup" - match 'data_files/admin' - match 'data_files/addFile' - match 'data_files/delFile' - match 'data_files/trash' + match "data_files/admin" + match "data_files/addFile" + match "data_files/delFile" + match "data_files/trash" - match 'contesters/recalc' + match "contesters/recalc" - match 'directories', to: "directories#show", id: 1 + match "directories", to: "directories#show", id: 1 - match 'gathers/refresh' - match 'gathers/latest/:game', to: "gathers#latest", via: :get - match 'gather', to: "gathers#latest", game: "ns2", via: :get + match "gathers/refresh" + match "gathers/latest/:game", to: "gathers#latest", via: :get + match "gather", to: "gathers#latest", game: "ns2", via: :get - match 'gatherers/:id/status', to: "gatherers#status", via: :post + match "gatherers/:id/status", to: "gatherers#status", via: :post - match 'groups/addUser' - match 'groups/delUser' + match "groups/addUser" + match "groups/delUser" - match 'movies/download' - match 'movies/preview' - match 'movies/snapshot' + match "movies/download" + match "movies/preview" + match "movies/snapshot" - match 'plugin/user' + match "plugin/user" - match 'users/forgot' - match 'users/recover' - match 'users/agenda' - match 'users/logout' - match 'users/login' + match "users/forgot" + match "users/recover" + match "users/agenda" + match "users/logout" + match "users/login" - match 'users/agenda' - match 'users/login' - match 'users/logout' - match 'users/popup' - match 'users/forgot', to: "users#forgot" + match "users/agenda" + match "users/login" + match "users/logout" + match "users/popup" + match "users/forgot", to: "users#forgot" - match 'votes/create' + match "votes/create" - match ':controller/:action', requirements: { action: /A-Za-z/ } - match ':controller/:action/:id' - match ':controller/:action/:id.:format' - match ':controller/:action/:id/:id2' + match ":controller/:action", requirements: { action: /A-Za-z/ } + match ":controller/:action/:id" + match ":controller/:action/:id.:format" + match ":controller/:action/:id/:id2" - match 'teamers/replace', to: 'teamers#replace', as: 'teamers_replace' + match "teamers/replace", to: "teamers#replace", as: "teamers_replace" end