Created
October 6, 2012 02:01
-
-
Save zamith/3843446 to your computer and use it in GitHub Desktop.
The power of clean code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UserTeamsController < ApplicationController | |
respond_to :html | |
def create | |
if is_a_coach? | |
create_a_team_for_the_coach | |
populate_flash condition: @coach_to_team_connection, | |
success_msg: t('flash.team.created.success'), | |
failure_msg: t('flash.team.created.error') | |
else | |
# TODO: Add player conditional branch | |
end | |
respond_with @coach_to_team_connection, location: root_path | |
end | |
private | |
def is_a_coach? | |
params[:commit] == t('static_page.home.coach') | |
end | |
def create_a_team_for_the_coach | |
if coach_has_no_team? | |
@team_role = TeamRole.get_role_for :head_coach | |
@team = Team.create_dummy | |
connect_coach_to_team | |
end | |
end | |
def coach_has_no_team? | |
current_user.teams.empty? | |
end | |
def connect_coach_to_team | |
@coach_to_team_connection = UserTeam.create user_id: current_user.id, | |
team_role_id: @team_role.id, | |
team_id: @team.id | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UserTeamsController < ApplicationController | |
def create | |
if params[:commit] == t('static_page.home.coach') | |
if current_user.teams.empty? | |
@team_role = TeamRole.find_by_name "Head Coach" | |
@team = Team.create name: "My Team" | |
if UserTeam.create user_id: current_user.id, team_role_id: @team_role.id, team_id: @team.id | |
flash[:notice] = t('flash.team.created.success') | |
else | |
flash[:error] = t('flash.team.created.error') | |
end | |
end | |
else | |
# TODO: Add player conditional branch | |
end | |
redirect_to root_path | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment