public
Description: The open source social networking platform in Ruby on Rails from the author of RailsSpace
Homepage: http://insoshi.com
Clone URL: git://github.com/insoshi/insoshi.git
Search Repo:
insoshi / app / controllers / activities_controller.rb
100644 109 lines (89 sloc) 2.578 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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