Class: ActiveMetadata::AttachmentsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/active_metadata/attachments_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



13
14
15
16
17
18
19
20
21
# File 'app/controllers/active_metadata/attachments_controller.rb', line 13

def create
  @document = params[:model_name].to_class.find(params[:model_id])
  @document.save_attachment_for(params[:field_name], params[:file], params[:starred], params[:group])
  
  #todo: if errors send back the correct answer
  respond_to do |format|
    format.js {render :json => {'success' => true}}
  end
end

#destroyObject



33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/active_metadata/attachments_controller.rb', line 33

def destroy
  @document = params[:model_name].to_class.find(params[:model_id])
  @document.delete_attachment(params[:id])
  
  #todo: if errors send back the correct answer
  respond_to do |format|
    # TODO redirect to index
    format.js
  end
end

#indexObject



4
5
6
7
8
9
10
11
# File 'app/controllers/active_metadata/attachments_controller.rb', line 4

def index
  @document = params[:model_name].to_class.find(params[:model_id])
   @attachments = @document.attachments_for params[:field_name]      
   respond_to do |format|
     format.html { render :layout => false}
     format.xml  { render :xml => @histories }
   end
end

#updateObject



23
24
25
26
27
28
29
30
31
# File 'app/controllers/active_metadata/attachments_controller.rb', line 23

def update
  @document = params[:model_name].to_class.find(params[:model_id])
  @document.update_attachment(params[:id],params[:file])
  
  #todo: if errors send back the correct answer
  respond_to do |format|
    format.js {render :json => {'success' => true}}
  end
end