Class: Cms::AttachmentsController

Inherits:
BaseController show all
Includes:
Cms::Attachments::Serving, ContentRenderingSupport
Defined in:
app/controllers/cms/attachments_controller.rb

Instance Method Summary collapse

Methods included from Cms::Attachments::Serving

#send_attachment, #send_attachments_with, send_attachments_with

Methods included from ContentRenderingSupport

#handle_access_denied_on_page, #handle_draft_not_found, #handle_not_found_on_page, #handle_server_error_on_page, #show_content_as_page

Methods inherited from BaseController

allow_guests_to

Methods inherited from ApplicationController

#no_browser_caching

Instance Method Details

#createObject



26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/cms/attachments_controller.rb', line 26

def create
  @attachment = Attachment.new(permitted_params)
  @attachment.published = true
  if @attachment.save
    render :partial => 'cms/attachments/attachment_wrapper', :locals => {:attachment => @attachment}
  else
    #TODO: render html error string
    render :inline => 'an error ocurred'
  end
end

#destroyObject



37
38
39
40
41
# File 'app/controllers/cms/attachments_controller.rb', line 37

def destroy
  @attachment = Attachment.find(params[:id])
  @attachment.destroy
  render :json => @attachment.id
end

#downloadObject

This handles serving files for attachments that don’t have a user specified path. If a path is defined, the ContentController#try_to_stream will handle it.

Users can only download files if they have permission to view it.



21
22
23
24
# File 'app/controllers/cms/attachments_controller.rb', line 21

def download
  @attachment = Attachment.find(params[:id])
  send_attachment(@attachment)
end

#showObject

Returns a specific version of an attachment. Used to display older versions in the editor interface.



11
12
13
14
15
# File 'app/controllers/cms/attachments_controller.rb', line 11

def show
  @attachment = Attachment.unscoped.find(params[:id])
  @attachment = @attachment.as_of_version(params[:version]) if params[:version]
  send_attachment(@attachment)
end