Module: RailsConnector::CmsAccessible

Included in:
DefaultCmsController
Defined in:
lib/rails_connector/cms_accessible.rb

Instance Method Summary collapse

Instance Method Details

#deliver_fileObject (protected)

Deliver the obj’s body as response by file or data. May respond with status 304 if a If-Modified-Since header is found.



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/rails_connector/cms_accessible.rb', line 97

def deliver_file
  if @obj.body_data_url
    redirect_to @obj.body_data_url
  elsif stale?(:last_modified => @obj.last_changed.utc)
    mime_type = @obj.mime_type
    mime_type += '; charset=utf-8' if mime_type =~ /^text\//

    if (filepath = @obj.body_data_path).present?
      send_file(File.expand_path(filepath), {
        :type => mime_type,
        :filename => @obj.filename,
        :disposition => 'inline',
      })
    else
      # generics should send its body, empty files should be delivered as
      # empty files - and not lead to an application error
      send_data @obj.body || '', :type => mime_type, :filename => @obj.filename, :disposition => 'inline'
    end
  end
end

#force_html_formatObject (protected)

Enforce “html” as template format.



72
73
74
# File 'lib/rails_connector/cms_accessible.rb', line 72

def force_html_format
  request.format = :html
end

#render_obj_error(status, name) ⇒ Object (protected)

This method is called when rendering an error caused by either #ensure_object_is_permitted or #ensure_object_is_active before filter. It renders an error template located in “errors/*.html.erb” with given HTTP status and content type “text/html” and with no layout. Overwrite this method to change the error page.



60
61
62
63
64
65
66
67
68
# File 'lib/rails_connector/cms_accessible.rb', line 60

def render_obj_error(status, name)
  force_html_format
  render(
    :template => "errors/#{status}_#{name}",
    :layout => false,
    :status => status,
    :content_type => Mime::HTML
  )
end