Class: DocumentsController

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

Constant Summary collapse

PER_PAGE =
20
SEND_FILE_METHOD =
:default

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.index_object_typeObject



81
82
83
# File 'app/controllers/documents_controller.rb', line 81

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

Instance Method Details

#createObject



22
23
24
25
26
# File 'app/controllers/documents_controller.rb', line 22

def create
  super do |format|
    format.all {redirect_to request.referer || home_path}
  end
end

#downloadObject

TODO: we have to add the mimetype as in videos_controller



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/controllers/documents_controller.rb', line 49

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

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

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

  # Ask Victor about the rationale of this:
  case SEND_FILE_METHOD
  when :apache then send_file_options[:x_sendfile] = true
  when :nginx then head(:x_accel_redirect => path.gsub(Rails.root, ''))
  end

  send_file(path, send_file_options)
end

#indexObject



12
13
14
15
16
17
18
19
20
# File 'app/controllers/documents_controller.rb', line 12

def index
  super do |format|
    if params[:no_layout].present?
      format.html { render :action => :index, :layout => false }      
    else  
      format.html { render :action => :index }
    end
  end
end

#showObject



35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/documents_controller.rb', line 35

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

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

#updateObject



28
29
30
31
32
33
# File 'app/controllers/documents_controller.rb', line 28

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