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

#determine_page_layout, #handle_access_denied_on_page, #handle_not_found_on_page, #handle_server_error_on_page

Methods included from PageHelper

#able_to?, #cms_content_editor, #cms_toolbar, #container, #container_has_block?, #current_page, #page_title, #render_breadcrumbs, #render_portlet

Methods included from PathHelper

#attachment_path_for, #cms_connectable_path, #cms_index_path_for, #cms_index_url_for, #cms_new_path_for, #cms_new_url_for, #cms_sortable_column_path, #edit_cms_connectable_path, #engine_for, #link_to_usages, #path_elements_for

Methods included from ErrorHandling

#handle_access_denied, #handle_server_error, #with_format

Instance Method Details

#createObject



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

def create
  @attachment = Attachment.new(params[:attachment])
  @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



39
40
41
42
43
# File 'app/controllers/cms/attachments_controller.rb', line 39

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.



23
24
25
26
# File 'app/controllers/cms/attachments_controller.rb', line 23

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.



13
14
15
16
17
# File 'app/controllers/cms/attachments_controller.rb', line 13

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