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.



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/rails_connector/cms_accessible.rb', line 93

def deliver_file
  if @obj.body_data_url
    redirect_to enforce_protocol_from_request(@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.



68
69
70
# File 'lib/rails_connector/cms_accessible.rb', line 68

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.



56
57
58
59
60
61
62
63
64
# File 'lib/rails_connector/cms_accessible.rb', line 56

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