1
0
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:
2015-10-23 08:53:29 -04:00
parent f204024b23
commit ad9ea9dc42
14 changed files with 76 additions and 72 deletions

View File

@@ -19,13 +19,13 @@ class MatchesController < ApplicationController
# GET /matches/1/edit # GET /matches/1/edit
def edit def edit
if user_signed_in?
else
redirect_to root_path
end
if params[:match] if params[:match]
@match = Match.find (params[:match]) @match = Match.find (params[:match])
end end
if current_user == @match.tournament.user
else
redirect_to root_path
end
if @match if @match
@w1 = Wrestler.find(@match.w1) @w1 = Wrestler.find(@match.w1)
@w2 = Wrestler.find(@match.w2) @w2 = Wrestler.find(@match.w2)
@@ -55,7 +55,7 @@ class MatchesController < ApplicationController
# PATCH/PUT /matches/1 # PATCH/PUT /matches/1
# PATCH/PUT /matches/1.json # PATCH/PUT /matches/1.json
def update def update
if user_signed_in? if current_user == @match.tournament.user
else else
redirect_to root_path redirect_to root_path
end end

View File

@@ -18,6 +18,9 @@ class MatsController < ApplicationController
if params[:tournament] if params[:tournament]
@tournament_field = params[:tournament] @tournament_field = params[:tournament]
@tournament = Tournament.find(params[:tournament]) @tournament = Tournament.find(params[:tournament])
if current_user != @tournament.user
redirect_to root_path
end
end end
end end
@@ -29,12 +32,11 @@ class MatsController < ApplicationController
# POST /mats # POST /mats
# POST /mats.json # POST /mats.json
def create def create
if user_signed_in?
else
redirect_to root_path
end
@mat = Mat.new(mat_params) @mat = Mat.new(mat_params)
@tournament = Tournament.find(mat_params[:tournament_id]) @tournament = Tournament.find(mat_params[:tournament_id])
if current_user != @tournament.user
redirect_to root_path
end
respond_to do |format| respond_to do |format|
if @mat.save if @mat.save
format.html { redirect_to @tournament, notice: 'Mat was successfully created.' } 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
# PATCH/PUT /mats/1.json # PATCH/PUT /mats/1.json
def update def update
if user_signed_in?
else
redirect_to root_path
end
@tournament = Tournament.find(@mat.tournament_id) @tournament = Tournament.find(@mat.tournament_id)
if current_user != @tournament.user
redirect_to root_path
end
respond_to do |format| respond_to do |format|
if @mat.update(mat_params) if @mat.update(mat_params)
format.html { redirect_to @tournament, notice: 'Mat was successfully updated.' } format.html { redirect_to @tournament, notice: 'Mat was successfully updated.' }
@@ -68,11 +69,10 @@ class MatsController < ApplicationController
# DELETE /mats/1 # DELETE /mats/1
# DELETE /mats/1.json # DELETE /mats/1.json
def destroy def destroy
if user_signed_in?
else
redirect_to root_path
end
@tournament = Tournament.find(@mat.tournament_id) @tournament = Tournament.find(@mat.tournament_id)
if current_user != @tournament.user
redirect_to root_path
end
@mat.destroy @mat.destroy
respond_to do |format| respond_to do |format|
format.html { redirect_to @tournament } format.html { redirect_to @tournament }

View File

@@ -32,12 +32,11 @@ class SchoolsController < ApplicationController
# POST /schools # POST /schools
# POST /schools.json # POST /schools.json
def create def create
if user_signed_in?
else
redirect_to root_path
end
@school = School.new(school_params) @school = School.new(school_params)
@tournament = Tournament.find(school_params[:tournament_id]) @tournament = Tournament.find(school_params[:tournament_id])
if current_user != @tournament.user
redirect_to root_path
end
respond_to do |format| respond_to do |format|
if @school.save if @school.save
format.html { redirect_to @tournament, notice: 'School was successfully created.' } 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
# PATCH/PUT /schools/1.json # PATCH/PUT /schools/1.json
def update def update
if user_signed_in?
else
redirect_to root_path
end
@tournament = Tournament.find(@school.tournament_id) @tournament = Tournament.find(@school.tournament_id)
if current_user != @tournament.user
redirect_to root_path
end
respond_to do |format| respond_to do |format|
if @school.update(school_params) if @school.update(school_params)
format.html { redirect_to @tournament, notice: 'School was successfully updated.' } format.html { redirect_to @tournament, notice: 'School was successfully updated.' }
@@ -71,11 +69,10 @@ class SchoolsController < ApplicationController
# DELETE /schools/1 # DELETE /schools/1
# DELETE /schools/1.json # DELETE /schools/1.json
def destroy def destroy
if user_signed_in?
else
redirect_to root_path
end
@tournament = Tournament.find(@school.tournament_id) @tournament = Tournament.find(@school.tournament_id)
if current_user != @tournament.user
redirect_to root_path
end
@school.destroy @school.destroy
respond_to do |format| respond_to do |format|
format.html { redirect_to @tournament } format.html { redirect_to @tournament }

View File

@@ -68,12 +68,11 @@ class StaticPagesController < ApplicationController
end end
def createCustomWeights def createCustomWeights
if user_signed_in? @tournament = Tournament.find(params[:tournament])
else if current_user != @tournament.user
redirect_to root_path redirect_to root_path
end end
@tournament = Tournament.find(params[:tournament]) @custom = params[:customValue].to_s
@custom = params[:customValue].to_s
@tournament.createCustomWeights(@custom) @tournament.createCustomWeights(@custom)
redirect_to "/tournaments/#{@tournament.id}" redirect_to "/tournaments/#{@tournament.id}"
@@ -92,6 +91,9 @@ class StaticPagesController < ApplicationController
elsif user_signed_in? elsif user_signed_in?
if params[:tournament] if params[:tournament]
@tournament = Tournament.find(params[:tournament]) @tournament = Tournament.find(params[:tournament])
if current_user != @tournament.user
redirect_to root_path
end
end end
if @tournament if @tournament
@tournament.generateMatchups @tournament.generateMatchups
@@ -108,6 +110,9 @@ class StaticPagesController < ApplicationController
end end
if params[:tournament] if params[:tournament]
@tournament = Tournament.find(params[:tournament]) @tournament = Tournament.find(params[:tournament])
if current_user != @tournament.user
redirect_to root_path
end
@tournament_id = @tournament.id @tournament_id = @tournament.id
@tournament_name = @tournament.name @tournament_name = @tournament.name
end end

View File

@@ -46,10 +46,9 @@ class TournamentsController < ApplicationController
# PATCH/PUT /tournaments/1 # PATCH/PUT /tournaments/1
# PATCH/PUT /tournaments/1.json # PATCH/PUT /tournaments/1.json
def update def update
if user_signed_in? if current_user != @tournament.user
else redirect_to root_path
redirect_to root_path end
end
respond_to do |format| respond_to do |format|
if @tournament.update(tournament_params) if @tournament.update(tournament_params)
format.html { redirect_to @tournament, notice: 'Tournament was successfully updated.' } format.html { redirect_to @tournament, notice: 'Tournament was successfully updated.' }
@@ -64,10 +63,9 @@ class TournamentsController < ApplicationController
# DELETE /tournaments/1 # DELETE /tournaments/1
# DELETE /tournaments/1.json # DELETE /tournaments/1.json
def destroy def destroy
if user_signed_in? if current_user != @tournament.user
else redirect_to root_path
redirect_to root_path end
end
@tournament.destroy @tournament.destroy
respond_to do |format| respond_to do |format|
format.html { redirect_to tournaments_url } format.html { redirect_to tournaments_url }

View File

@@ -37,13 +37,11 @@ class WeightsController < ApplicationController
# POST /weights # POST /weights
# POST /weights.json # POST /weights.json
def create def create
if user_signed_in?
else
redirect_to root_path
end
@weight = Weight.new(weight_params) @weight = Weight.new(weight_params)
@tournament = Tournament.find(weight_params[:tournament_id]) @tournament = Tournament.find(weight_params[:tournament_id])
if current_user != @tournament.user
redirect_to root_path
end
respond_to do |format| respond_to do |format|
if @weight.save if @weight.save
format.html { redirect_to @tournament, notice: 'Weight was successfully created.' } 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
# PATCH/PUT /weights/1.json # PATCH/PUT /weights/1.json
def update def update
if user_signed_in?
else
redirect_to root_path
end
@tournament = Tournament.find(@weight.tournament_id) @tournament = Tournament.find(@weight.tournament_id)
if current_user != @tournament.user
redirect_to root_path
end
respond_to do |format| respond_to do |format|
if @weight.update(weight_params) if @weight.update(weight_params)
format.html { redirect_to @tournament, notice: 'Weight was successfully updated.' } format.html { redirect_to @tournament, notice: 'Weight was successfully updated.' }
@@ -77,11 +74,10 @@ class WeightsController < ApplicationController
# DELETE /weights/1 # DELETE /weights/1
# DELETE /weights/1.json # DELETE /weights/1.json
def destroy def destroy
if user_signed_in?
else
redirect_to root_path
end
@tournament = Tournament.find(@weight.tournament_id) @tournament = Tournament.find(@weight.tournament_id)
if current_user != @tournament.user
redirect_to root_path
end
@weight.destroy @weight.destroy
respond_to do |format| respond_to do |format|
format.html { redirect_to @tournament } format.html { redirect_to @tournament }

View File

@@ -43,11 +43,10 @@ class WrestlersController < ApplicationController
# POST /wrestlers # POST /wrestlers
# POST /wrestlers.json # POST /wrestlers.json
def create def create
if user_signed_in?
else
redirect_to root_path
end
@wrestler = Wrestler.new(wrestler_params) @wrestler = Wrestler.new(wrestler_params)
if current_user != @wrestler.tournament.user
redirect_to root_path
end
@school = School.find(wrestler_params[:school_id]) @school = School.find(wrestler_params[:school_id])
respond_to do |format| respond_to do |format|
if @wrestler.save if @wrestler.save
@@ -63,9 +62,8 @@ class WrestlersController < ApplicationController
# PATCH/PUT /wrestlers/1 # PATCH/PUT /wrestlers/1
# PATCH/PUT /wrestlers/1.json # PATCH/PUT /wrestlers/1.json
def update def update
if user_signed_in? if current_user != @wrestler.tournament.user
else redirect_to root_path
redirect_to root_path
end end
@school = School.find(@wrestler.school_id) @school = School.find(@wrestler.school_id)
respond_to do |format| respond_to do |format|
@@ -82,9 +80,8 @@ class WrestlersController < ApplicationController
# DELETE /wrestlers/1 # DELETE /wrestlers/1
# DELETE /wrestlers/1.json # DELETE /wrestlers/1.json
def destroy def destroy
if user_signed_in? if current_user != @wrestler.tournament.user
else redirect_to root_path
redirect_to root_path
end end
@school = School.find(@wrestler.school_id) @school = School.find(@wrestler.school_id)
@wrestler.destroy @wrestler.destroy

View File

@@ -8,6 +8,7 @@ class Tournament < ActiveRecord::Base
has_many :mats, dependent: :destroy has_many :mats, dependent: :destroy
has_many :wrestlers, through: :weights has_many :wrestlers, through: :weights
has_many :matches, dependent: :destroy has_many :matches, dependent: :destroy
belongs_to :user
def tournament_types def tournament_types
["Pool to bracket"] ["Pool to bracket"]

View File

@@ -1,6 +1,8 @@
class User < ActiveRecord::Base class User < ActiveRecord::Base
# Include default devise modules. Others available are: # Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable # :confirmable, :lockable, :timeoutable and :omniauthable
has_many :tournaments
devise :database_authenticatable, :registerable, devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable :recoverable, :rememberable, :trackable, :validatable
end end

View File

@@ -1,5 +1,4 @@
<h2>Sign up</h2> <h2>Sign up</h2>
<% if user_signed_in? %>
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %> <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %> <%= devise_error_messages! %>
@@ -13,7 +12,6 @@
<%= f.password_field :password_confirmation %></div> <%= f.password_field :password_confirmation %></div>
<div><%= f.submit "Sign up" %></div> <div><%= f.submit "Sign up" %></div>
<% end %>
<% end %> <% end %>
<%= render "devise/shared/links" %> <%= render "devise/shared/links" %>

View File

@@ -33,6 +33,7 @@
</div> </div>
<br> <br>
<br> <br>
<%= f.hidden_field :user_id, :value => current_user.id %>
<div class="actions"> <div class="actions">
<%= f.submit 'Submit',:class=>"btn btn-success" %> <%= f.submit 'Submit',:class=>"btn btn-success" %>
</div> </div>

View File

@@ -0,0 +1,6 @@
class AddUserIdToTournaments < ActiveRecord::Migration
def change
add_column :tournaments, :user_id, :integer
add_index :tournaments, :user_id
end
end

View File

@@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # 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| create_table "matches", force: :cascade do |t|
t.integer "w1" t.integer "w1"
@@ -66,8 +66,11 @@ ActiveRecord::Schema.define(version: 20150630170119) do
t.datetime "updated_at" t.datetime "updated_at"
t.text "tournament_type" t.text "tournament_type"
t.text "weigh_in_ref" t.text "weigh_in_ref"
t.integer "user_id"
end end
add_index "tournaments", ["user_id"], name: "index_tournaments_on_user_id"
create_table "users", force: :cascade do |t| create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false t.string "encrypted_password", default: "", null: false

View File

@@ -6,8 +6,8 @@
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first) # Mayor.create(name: 'Emanuel', city: cities.first)
if Rails.env.development? if Rails.env.development?
User.create(email: 'test@test.com', password: 'password', password_confirmation: 'password') 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') 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: 200, name: 'Central Crossing', tournament_id: 200)
School.create(id: 201, name: 'Turd Town', tournament_id: 200) School.create(id: 201, name: 'Turd Town', tournament_id: 200)
School.create(id: 202, name: 'Shit Show', tournament_id: 200) School.create(id: 202, name: 'Shit Show', tournament_id: 200)