mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-25 01:14:43 +00:00
First crack at setting an owner for the tournament
This commit is contained in:
@@ -19,13 +19,13 @@ class MatchesController < ApplicationController
|
||||
|
||||
# GET /matches/1/edit
|
||||
def edit
|
||||
if user_signed_in?
|
||||
else
|
||||
redirect_to root_path
|
||||
end
|
||||
if params[:match]
|
||||
@match = Match.find (params[:match])
|
||||
end
|
||||
if current_user == @match.tournament.user
|
||||
else
|
||||
redirect_to root_path
|
||||
end
|
||||
if @match
|
||||
@w1 = Wrestler.find(@match.w1)
|
||||
@w2 = Wrestler.find(@match.w2)
|
||||
@@ -55,7 +55,7 @@ class MatchesController < ApplicationController
|
||||
# PATCH/PUT /matches/1
|
||||
# PATCH/PUT /matches/1.json
|
||||
def update
|
||||
if user_signed_in?
|
||||
if current_user == @match.tournament.user
|
||||
else
|
||||
redirect_to root_path
|
||||
end
|
||||
|
||||
@@ -18,6 +18,9 @@ class MatsController < ApplicationController
|
||||
if params[:tournament]
|
||||
@tournament_field = params[:tournament]
|
||||
@tournament = Tournament.find(params[:tournament])
|
||||
if current_user != @tournament.user
|
||||
redirect_to root_path
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -29,12 +32,11 @@ class MatsController < ApplicationController
|
||||
# POST /mats
|
||||
# POST /mats.json
|
||||
def create
|
||||
if user_signed_in?
|
||||
else
|
||||
redirect_to root_path
|
||||
end
|
||||
@mat = Mat.new(mat_params)
|
||||
@tournament = Tournament.find(mat_params[:tournament_id])
|
||||
if current_user != @tournament.user
|
||||
redirect_to root_path
|
||||
end
|
||||
respond_to do |format|
|
||||
if @mat.save
|
||||
format.html { redirect_to @tournament, notice: 'Mat was successfully created.' }
|
||||
@@ -49,11 +51,10 @@ class MatsController < ApplicationController
|
||||
# PATCH/PUT /mats/1
|
||||
# PATCH/PUT /mats/1.json
|
||||
def update
|
||||
if user_signed_in?
|
||||
else
|
||||
@tournament = Tournament.find(@mat.tournament_id)
|
||||
if current_user != @tournament.user
|
||||
redirect_to root_path
|
||||
end
|
||||
@tournament = Tournament.find(@mat.tournament_id)
|
||||
respond_to do |format|
|
||||
if @mat.update(mat_params)
|
||||
format.html { redirect_to @tournament, notice: 'Mat was successfully updated.' }
|
||||
@@ -68,11 +69,10 @@ class MatsController < ApplicationController
|
||||
# DELETE /mats/1
|
||||
# DELETE /mats/1.json
|
||||
def destroy
|
||||
if user_signed_in?
|
||||
else
|
||||
@tournament = Tournament.find(@mat.tournament_id)
|
||||
if current_user != @tournament.user
|
||||
redirect_to root_path
|
||||
end
|
||||
@tournament = Tournament.find(@mat.tournament_id)
|
||||
@mat.destroy
|
||||
respond_to do |format|
|
||||
format.html { redirect_to @tournament }
|
||||
|
||||
@@ -32,12 +32,11 @@ class SchoolsController < ApplicationController
|
||||
# POST /schools
|
||||
# POST /schools.json
|
||||
def create
|
||||
if user_signed_in?
|
||||
else
|
||||
redirect_to root_path
|
||||
end
|
||||
@school = School.new(school_params)
|
||||
@tournament = Tournament.find(school_params[:tournament_id])
|
||||
if current_user != @tournament.user
|
||||
redirect_to root_path
|
||||
end
|
||||
respond_to do |format|
|
||||
if @school.save
|
||||
format.html { redirect_to @tournament, notice: 'School was successfully created.' }
|
||||
@@ -52,11 +51,10 @@ class SchoolsController < ApplicationController
|
||||
# PATCH/PUT /schools/1
|
||||
# PATCH/PUT /schools/1.json
|
||||
def update
|
||||
if user_signed_in?
|
||||
else
|
||||
@tournament = Tournament.find(@school.tournament_id)
|
||||
if current_user != @tournament.user
|
||||
redirect_to root_path
|
||||
end
|
||||
@tournament = Tournament.find(@school.tournament_id)
|
||||
respond_to do |format|
|
||||
if @school.update(school_params)
|
||||
format.html { redirect_to @tournament, notice: 'School was successfully updated.' }
|
||||
@@ -71,11 +69,10 @@ class SchoolsController < ApplicationController
|
||||
# DELETE /schools/1
|
||||
# DELETE /schools/1.json
|
||||
def destroy
|
||||
if user_signed_in?
|
||||
else
|
||||
@tournament = Tournament.find(@school.tournament_id)
|
||||
if current_user != @tournament.user
|
||||
redirect_to root_path
|
||||
end
|
||||
@tournament = Tournament.find(@school.tournament_id)
|
||||
@school.destroy
|
||||
respond_to do |format|
|
||||
format.html { redirect_to @tournament }
|
||||
|
||||
@@ -68,11 +68,10 @@ class StaticPagesController < ApplicationController
|
||||
end
|
||||
|
||||
def createCustomWeights
|
||||
if user_signed_in?
|
||||
else
|
||||
@tournament = Tournament.find(params[:tournament])
|
||||
if current_user != @tournament.user
|
||||
redirect_to root_path
|
||||
end
|
||||
@tournament = Tournament.find(params[:tournament])
|
||||
@custom = params[:customValue].to_s
|
||||
@tournament.createCustomWeights(@custom)
|
||||
|
||||
@@ -92,6 +91,9 @@ class StaticPagesController < ApplicationController
|
||||
elsif user_signed_in?
|
||||
if params[:tournament]
|
||||
@tournament = Tournament.find(params[:tournament])
|
||||
if current_user != @tournament.user
|
||||
redirect_to root_path
|
||||
end
|
||||
end
|
||||
if @tournament
|
||||
@tournament.generateMatchups
|
||||
@@ -108,6 +110,9 @@ class StaticPagesController < ApplicationController
|
||||
end
|
||||
if params[:tournament]
|
||||
@tournament = Tournament.find(params[:tournament])
|
||||
if current_user != @tournament.user
|
||||
redirect_to root_path
|
||||
end
|
||||
@tournament_id = @tournament.id
|
||||
@tournament_name = @tournament.name
|
||||
end
|
||||
|
||||
@@ -46,8 +46,7 @@ class TournamentsController < ApplicationController
|
||||
# PATCH/PUT /tournaments/1
|
||||
# PATCH/PUT /tournaments/1.json
|
||||
def update
|
||||
if user_signed_in?
|
||||
else
|
||||
if current_user != @tournament.user
|
||||
redirect_to root_path
|
||||
end
|
||||
respond_to do |format|
|
||||
@@ -64,8 +63,7 @@ class TournamentsController < ApplicationController
|
||||
# DELETE /tournaments/1
|
||||
# DELETE /tournaments/1.json
|
||||
def destroy
|
||||
if user_signed_in?
|
||||
else
|
||||
if current_user != @tournament.user
|
||||
redirect_to root_path
|
||||
end
|
||||
@tournament.destroy
|
||||
|
||||
@@ -37,13 +37,11 @@ class WeightsController < ApplicationController
|
||||
# POST /weights
|
||||
# POST /weights.json
|
||||
def create
|
||||
if user_signed_in?
|
||||
else
|
||||
redirect_to root_path
|
||||
end
|
||||
@weight = Weight.new(weight_params)
|
||||
@tournament = Tournament.find(weight_params[:tournament_id])
|
||||
|
||||
if current_user != @tournament.user
|
||||
redirect_to root_path
|
||||
end
|
||||
respond_to do |format|
|
||||
if @weight.save
|
||||
format.html { redirect_to @tournament, notice: 'Weight was successfully created.' }
|
||||
@@ -58,11 +56,10 @@ class WeightsController < ApplicationController
|
||||
# PATCH/PUT /weights/1
|
||||
# PATCH/PUT /weights/1.json
|
||||
def update
|
||||
if user_signed_in?
|
||||
else
|
||||
@tournament = Tournament.find(@weight.tournament_id)
|
||||
if current_user != @tournament.user
|
||||
redirect_to root_path
|
||||
end
|
||||
@tournament = Tournament.find(@weight.tournament_id)
|
||||
respond_to do |format|
|
||||
if @weight.update(weight_params)
|
||||
format.html { redirect_to @tournament, notice: 'Weight was successfully updated.' }
|
||||
@@ -77,11 +74,10 @@ class WeightsController < ApplicationController
|
||||
# DELETE /weights/1
|
||||
# DELETE /weights/1.json
|
||||
def destroy
|
||||
if user_signed_in?
|
||||
else
|
||||
@tournament = Tournament.find(@weight.tournament_id)
|
||||
if current_user != @tournament.user
|
||||
redirect_to root_path
|
||||
end
|
||||
@tournament = Tournament.find(@weight.tournament_id)
|
||||
@weight.destroy
|
||||
respond_to do |format|
|
||||
format.html { redirect_to @tournament }
|
||||
|
||||
@@ -43,11 +43,10 @@ class WrestlersController < ApplicationController
|
||||
# POST /wrestlers
|
||||
# POST /wrestlers.json
|
||||
def create
|
||||
if user_signed_in?
|
||||
else
|
||||
@wrestler = Wrestler.new(wrestler_params)
|
||||
if current_user != @wrestler.tournament.user
|
||||
redirect_to root_path
|
||||
end
|
||||
@wrestler = Wrestler.new(wrestler_params)
|
||||
@school = School.find(wrestler_params[:school_id])
|
||||
respond_to do |format|
|
||||
if @wrestler.save
|
||||
@@ -63,8 +62,7 @@ class WrestlersController < ApplicationController
|
||||
# PATCH/PUT /wrestlers/1
|
||||
# PATCH/PUT /wrestlers/1.json
|
||||
def update
|
||||
if user_signed_in?
|
||||
else
|
||||
if current_user != @wrestler.tournament.user
|
||||
redirect_to root_path
|
||||
end
|
||||
@school = School.find(@wrestler.school_id)
|
||||
@@ -82,8 +80,7 @@ class WrestlersController < ApplicationController
|
||||
# DELETE /wrestlers/1
|
||||
# DELETE /wrestlers/1.json
|
||||
def destroy
|
||||
if user_signed_in?
|
||||
else
|
||||
if current_user != @wrestler.tournament.user
|
||||
redirect_to root_path
|
||||
end
|
||||
@school = School.find(@wrestler.school_id)
|
||||
|
||||
@@ -8,6 +8,7 @@ class Tournament < ActiveRecord::Base
|
||||
has_many :mats, dependent: :destroy
|
||||
has_many :wrestlers, through: :weights
|
||||
has_many :matches, dependent: :destroy
|
||||
belongs_to :user
|
||||
|
||||
def tournament_types
|
||||
["Pool to bracket"]
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
class User < ActiveRecord::Base
|
||||
# Include default devise modules. Others available are:
|
||||
# :confirmable, :lockable, :timeoutable and :omniauthable
|
||||
has_many :tournaments
|
||||
|
||||
devise :database_authenticatable, :registerable,
|
||||
:recoverable, :rememberable, :trackable, :validatable
|
||||
end
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<h2>Sign up</h2>
|
||||
<% if user_signed_in? %>
|
||||
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
|
||||
<%= devise_error_messages! %>
|
||||
|
||||
@@ -14,6 +13,5 @@
|
||||
|
||||
<div><%= f.submit "Sign up" %></div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<%= render "devise/shared/links" %>
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
</div>
|
||||
<br>
|
||||
<br>
|
||||
<%= f.hidden_field :user_id, :value => current_user.id %>
|
||||
<div class="actions">
|
||||
<%= f.submit 'Submit',:class=>"btn btn-success" %>
|
||||
</div>
|
||||
|
||||
6
db/migrate/20151023123932_add_user_id_to_tournaments.rb
Normal file
6
db/migrate/20151023123932_add_user_id_to_tournaments.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
class AddUserIdToTournaments < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :tournaments, :user_id, :integer
|
||||
add_index :tournaments, :user_id
|
||||
end
|
||||
end
|
||||
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20150630170119) do
|
||||
ActiveRecord::Schema.define(version: 20151023123932) do
|
||||
|
||||
create_table "matches", force: :cascade do |t|
|
||||
t.integer "w1"
|
||||
@@ -66,8 +66,11 @@ ActiveRecord::Schema.define(version: 20150630170119) do
|
||||
t.datetime "updated_at"
|
||||
t.text "tournament_type"
|
||||
t.text "weigh_in_ref"
|
||||
t.integer "user_id"
|
||||
end
|
||||
|
||||
add_index "tournaments", ["user_id"], name: "index_tournaments_on_user_id"
|
||||
|
||||
create_table "users", force: :cascade do |t|
|
||||
t.string "email", default: "", null: false
|
||||
t.string "encrypted_password", default: "", null: false
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
|
||||
# Mayor.create(name: 'Emanuel', city: cities.first)
|
||||
if Rails.env.development?
|
||||
User.create(email: 'test@test.com', password: 'password', password_confirmation: 'password')
|
||||
Tournament.create(id: 200, name: 'test', address: 'some place', director: 'some guy', director_email: 'hismail@email.com', tournament_type: 'Pool to bracket')
|
||||
User.create(id: 1, email: 'test@test.com', password: 'password', password_confirmation: 'password')
|
||||
Tournament.create(id: 200, name: 'test', address: 'some place', director: 'some guy', director_email: 'hismail@email.com', tournament_type: 'Pool to bracket', user_id: 1)
|
||||
School.create(id: 200, name: 'Central Crossing', tournament_id: 200)
|
||||
School.create(id: 201, name: 'Turd Town', tournament_id: 200)
|
||||
School.create(id: 202, name: 'Shit Show', tournament_id: 200)
|
||||
|
||||
Reference in New Issue
Block a user