AnnotationsController

Public Instance Methods

create() click to toggle source

POST /annotations POST /annotations.xml

    # File lib/app/controllers/annotations_controller.rb, line 49
49:   def create
50:     if params[:annotation][:source_type].blank? and params[:annotation][:source_id].blank?
51:       if logged_in?
52:         params[:annotation][:source_type] = current_user.class.name
53:         params[:annotation][:source_id] = current_user.id
54:       end
55:     end
56:     
57:     @annotation = Annotation.new(params[:annotation])
58:     @annotation.annotatable = @annotatable
59: 
60:     respond_to do |format|
61:       if @annotation.save
62:         flash[:notice] = 'Annotation was successfully created.'
63:         format.html { redirect_to :back }
64:         format.xml  { render :xml => @annotation, :status => :created, :location => @annotation }
65:       else
66:         format.html { render :action => "new" }
67:         format.xml  { render :xml => @annotation.errors, :status => :unprocessable_entity }
68:       end
69:     end
70:   end
create_multiple() click to toggle source

POST /annotations/create_multiple POST /annotations/create_multiple.xml

    # File lib/app/controllers/annotations_controller.rb, line 74
74:   def create_multiple
75:     if params[:annotation][:source_type].blank? and params[:annotation][:source_id].blank?
76:       if logged_in?
77:         params[:annotation][:source_type] = current_user.class.name
78:         params[:annotation][:source_id] = current_user.id
79:       end
80:     end
81:     
82:     success, annotations, errors = Annotation.create_multiple(params[:annotation], params[:separator])
83: 
84:     respond_to do |format|
85:       if success
86:         flash[:notice] = 'Annotations were successfully created.'
87:         format.html { redirect_to :back }
88:         format.xml  { render :xml => annotations, :status => :created, :location => @annotatable }
89:       else
90:         flash[:error] = 'Some or all annotations failed to be created.'
91:         format.html { redirect_to :back }
92:         format.xml  { render :xml => annotations + errors, :status => :unprocessable_entity }
93:       end
94:     end
95:   end
destroy() click to toggle source

DELETE /annotations/1 DELETE /annotations/1.xml

     # File lib/app/controllers/annotations_controller.rb, line 120
120:   def destroy
121:     @annotation.destroy
122: 
123:     respond_to do |format|
124:       flash[:notice] = 'Annotation successfully deleted.'
125:       format.html { redirect_to :back }
126:       format.xml  { head :ok }
127:     end
128:   end
edit() click to toggle source

GET /annotations/1/edit

    # File lib/app/controllers/annotations_controller.rb, line 98
98:   def edit
99:   end
index() click to toggle source

GET /annotations GET /annotations.xml

    # File lib/app/controllers/annotations_controller.rb, line 11
11:   def index
12:     params[:num] ||= 50
13:     
14:     @annotations =  
15:     if @annotatable.nil?
16:       Annotation.find(:all, :limit => params[:num])      
17:     else
18:       @annotatable.latest_annotations(params[:num])
19:     end
20: 
21:     respond_to do |format|
22:       format.html # index.html.erb
23:       format.xml  { render :xml => @annotations }
24:     end
25:   end
new() click to toggle source

GET /annotations/new GET /annotations/new.xml

    # File lib/app/controllers/annotations_controller.rb, line 38
38:   def new
39:     @annotation = Annotation.new
40: 
41:     respond_to do |format|
42:       format.html # new.html.erb
43:       format.xml  { render :xml => @annotation }
44:     end
45:   end
show() click to toggle source

GET /annotations/1 GET /annotations/1.xml

    # File lib/app/controllers/annotations_controller.rb, line 29
29:   def show
30:     respond_to do |format|
31:       format.html # show.html.erb
32:       format.xml  { render :xml => @annotation }
33:     end
34:   end
update() click to toggle source

PUT /annotations/1 PUT /annotations/1.xml

     # File lib/app/controllers/annotations_controller.rb, line 103
103:   def update
104:     @annotation.value = params[:annotation][:value]
105:     @annotation.version_creator_id = current_user.id
106:     respond_to do |format|
107:       if @annotation.save
108:         flash[:notice] = 'Annotation was successfully updated.'
109:         format.html { redirect_to :back }
110:         format.xml  { head :ok }
111:       else
112:         format.html { render :action => "edit" }
113:         format.xml  { render :xml => @annotation.errors, :status => :unprocessable_entity }
114:       end
115:     end
116:   end

Protected Instance Methods

authorise_action() click to toggle source

Currently only checks that the source of the annotation matches the current user

     # File lib/app/controllers/annotations_controller.rb, line 150
150:   def authorise_action
151:     if !logged_in? or (@annotation.source != current_user)
152:       # TODO: return either a 401 or 403 depending on authentication
153:       respond_to do |format|
154:         flash[:error] = 'You are not allowed to perform this action.'
155:         format.html { redirect_to :back }
156:         format.xml  { head :forbidden }
157:       end
158:       return false
159:     end
160:     return true
161:   end
find_annotatable() click to toggle source

(Not documented)

     # File lib/app/controllers/annotations_controller.rb, line 136
136:   def find_annotatable
137:     @annotatable = nil
138:     
139:     if params[:annotation]
140:       @annotatable = Annotation.find_annotatable(params[:annotation][:annotatable_type], params[:annotation][:annotatable_id])
141:     end
142:     
143:     # If still nil try again with alternative params
144:     if @annotatable.nil?
145:       @annotatable = Annotation.find_annotatable(params[:annotatable_type], params[:annotatable_id])
146:     end
147:   end
find_annotation() click to toggle source

(Not documented)

     # File lib/app/controllers/annotations_controller.rb, line 132
132:   def find_annotation
133:     @annotation = Annotation.find(params[:id])
134:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.