Skip to content

Instantly share code, notes, and snippets.

@JFickel
Created September 2, 2012 01:09
Show Gist options
  • Select an option

  • Save JFickel/3593067 to your computer and use it in GitHub Desktop.

Select an option

Save JFickel/3593067 to your computer and use it in GitHub Desktop.
Teams controller
class TeamsController < ApplicationController
before_filter :only => [:edit, :update, :destroy] do |action|
action.redirect_if_not_team_admin(Team.find(params[:id]), @current_user)
end
def index
@teams = Team.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @teams }
end
end
# GET /teams/1
# GET /teams/1.json
def show
@team = Team.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @team }
end
end
# GET /teams/new
# GET /teams/new.json
def new
@team = Team.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @team }
end
end
# GET /teams/1/edit
def edit
@team = Team.find(params[:id])
end
# POST /teams
# POST /teams.json
def create
@team = Team.new(params[:team])
@team_role = TeamRole.new(user_id: session[:user_id], team_id: params[:team][:id], admin: true)
respond_to do |format|
if @team.save
@team_role.save
format.html { redirect_to @team, notice: 'Team was successfully created.' }
format.json { render json: @team, status: :created, location: @team }
else
format.html { render action: "new" }
format.json { render json: @team.errors, status: :unprocessable_entity }
end
end
end
# PUT /teams/1
# PUT /teams/1.json
def update
@team = Team.find(params[:id])
respond_to do |format|
if @team.update_attributes(params[:team])
format.html { redirect_to @team, notice: 'Team was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @team.errors, status: :unprocessable_entity }
end
end
end
# DELETE /teams/1
# DELETE /teams/1.json
def destroy
@team = Team.find(params[:id])
@team.destroy
respond_to do |format|
format.html { redirect_to teams_url }
format.json { head :no_content }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment