class ActivitiesController < ApplicationController
before_filter :not_implemented, :except => [:destroy]
before_filter :authorize_user, :only => :destroy
# GET /activities
# GET /activities.xml
def index
@activities = Activity.find(:all)
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @activities }
end
end
# GET /activities/1
# GET /activities/1.xml
def show
@activity = Activity.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @activity }
end
end
# GET /activities/new
# GET /activities/new.xml
def new
@activity = Activity.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @activity }
end
end
# GET /activities/1/edit
def edit
@activity = Activity.find(params[:id])
end
# POST /activities
# POST /activities.xml
def create
@activity = Activity.new(params[:event])
respond_to do |format|
if @activity.save
flash[:notice] = 'Activity was successfully created.'
format.html { redirect_to(@activity) }
format.xml { render :xml => @activity, :status => :created,
:location => @activity }
else
format.html { render :action => "new" }
format.xml { render :xml => @activity.errors,
:status => :unprocessable_entity }
end
end
end
# PUT /activities/1
# PUT /activities/1.xml
def update
@activity = Activity.find(params[:id])
respond_to do |format|
if @activity.update_attributes(params[:event])
flash[:notice] = 'Activity was successfully updated.'
format.html { redirect_to(@activity) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @activity.errors,
:status => :unprocessable_entity }
end
end
end
# DELETE /activities/1
# DELETE /activities/1.xml
def destroy
@activity.destroy
flash[:success] = "Activity deleted"
respond_to do |format|
format.html { redirect_to(person_url(current_person)) }
format.xml { head :ok }
end
end
private
def not_implemented
flash[:error] = "Not implemented"
redirect_to home_url
end
def authorize_user
@activity = Activity.find(params[:id])
unless current_person?(@activity.person)
redirect_to home_url
end
end
end