Class: DocumentsController

Inherits:
ApplicationController
  • Object
show all
Includes:
SocialStream::Controllers::Objects
Defined in:
app/controllers/documents_controller.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.index_object_typeObject



84
85
86
# File 'app/controllers/documents_controller.rb', line 84

def index_object_type
  [ :Audio, :Video, :Picture, :Document ]
end

Instance Method Details

#createObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/documents_controller.rb', line 18

def create
  super do |format|
    format.json { render :json => resource }
    format.js
    format.all {
      if resource.new_record?
        render action: :new
      else
        redirect = 
          ( request.referer.present? ?
            ( request.referer =~ /new$/ ?
              resource :
              request.referer ) :
            home_path )

        redirect_to redirect
      end
    }
  end
end

#downloadObject

TODO: we have to add the mimetype as in videos_controller



64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/controllers/documents_controller.rb', line 64

def download
  path = @document.file.path(params[:style])

  head(:not_found) and return unless File.exist?(path)

  send_file_options = {
    :filename => @document.file_file_name,
    :type => @document.file_content_type
  }

  send_file(path, send_file_options)
end

#indexObject



6
7
8
9
10
11
12
13
14
15
16
# File 'app/controllers/documents_controller.rb', line 6

def index
  respond_to do |format|
    format.html {
      collection

      render collection if request.xhr?
    }

    format.json { render :json => collection }
  end
end

#showObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/controllers/documents_controller.rb', line 46

def show
  respond_to do |format|
    format.html {render :action => :show}
    format.json {render :json => resource }
    format.any {
      path = resource.file.path(params[:style] || params[:format])

      head(:not_found) and return unless File.exist?(path)

      send_file path,
               :filename => resource.file_file_name,
               :disposition => "inline",
               :type => request.format
    }
  end
end

#updateObject



39
40
41
42
43
44
# File 'app/controllers/documents_controller.rb', line 39

def update
  update! do |success, failure|
    failure.html { render :action => :show }
    success.html { render :action => :show }
  end
end