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



94
95
96
# File 'app/controllers/documents_controller.rb', line 94

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

Instance Method Details

#createObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/documents_controller.rb', line 35

def create
  super do |format|
    format.json { render :json => resource.to_json(helper: self) }
    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

#destroyObject



63
64
65
66
67
68
69
70
71
# File 'app/controllers/documents_controller.rb', line 63

def destroy
  super do |format|
    format.html {
      redirect_to :home
    }

    format.js
  end
end

#downloadObject

TODO: we have to add the mimetype as in videos_controller



74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/controllers/documents_controller.rb', line 74

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.to_json(helper: self) }
  end
end

#showObject



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

def show
  respond_to do |format|
    format.html {render :action => :show}
    format.json {render :json => resource.to_json(helper: self) }
    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



56
57
58
59
60
61
# File 'app/controllers/documents_controller.rb', line 56

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