Class ApplicationController
In: app/controllers/application.rb
Parent: ActionController::Base

Application

This controller is the bridge between client HTTP requests and Code Blue, examining request data and returning appropriate project data.

Environment

Filters added to this controller will be run for all controllers in the application.

All methods in this class are available to all controllers.

Class and instance variables within this controller are accessible only during the lifetime of the current page request, they do not persist across multiple requests.

Methods

Attributes

request_id  [RW]  Accessor methods.

Public Class methods

Get and set global variables.

Variables set here are available only within the current page request process.

This method uses a variable length parameter list; the first two arguments are required, while the third argument is optional:

  • model
  • variable
  • value

Global variables are assigned using the interface method g() in the following way:

  • g(model, variable, value)

for example:

  • g(‘content’, ‘index’, TRUE)

Global variables are accessed in the following way:

  • g(model, variable)

for example:

  • g(‘content’, ‘index’)

[Source]

     # File app/controllers/application.rb, line 201
201:   def self.global_variable (
202:     arguments
203:   )
204:     model    = arguments[0]
205:     variable = arguments[1]
206:     value    = arguments[2] if (arguments[2])
207: 
208:     # Create a hash to house global variables, on a per model basis.
209:     @v["#{model}"] = {} if (!@v["#{model}"])
210: 
211:     # Assign a global variable.
212:     if (3 == arguments.size)
213:       @v["#{model}"]["#{variable}"] = value
214:       result = value
215:     # Return the value of a global variable, if it exists.
216:     elsif (@v["#{model}"]["#{variable}"])
217:       result = @v["#{model}"]["#{variable}"]
218:     # The requested variable does not exist.
219:     else
220:       result = FALSE
221:     end
222: 
223:     return result
224:   end

Public Instance methods

Compress the response.

[Source]

    # File app/controllers/application.rb, line 39
39:   def compress
40:     if (!is_download(request.env['PATH_INFO']))
41:       # Determine if the browser accepts compressed responses.
42:       accepts = request.env['HTTP_ACCEPT_ENCODING']
43:       return if !(accepts && accepts =~ /(x-gzip|gzip)/)
44:       encoding = $1
45:     
46:       output = StringIO.new
47:       def output.close
48:         rewind
49:       end
50:     
51:       # Compress the response body into a string.
52:       gz = Zlib::GzipWriter.new(output)
53:       gz.write(response.body)
54:       gz.close
55:   
56:       # If the compressed string is shorter than the response then substitute it
57:       # for the response and update the encoding.
58:       if (output.length < response.body.length)
59:         response.body = output.string
60:         response.headers['Content-encoding'] = encoding
61:       end
62:     end
63:   end

Setup the application environment and process this URL request.

[Source]

     # File app/controllers/application.rb, line 69
 69:   def  indexindex
 70:     build_start = Time.now.to_f
 71: 
 72: 
 73:     # Configure the runtime environment for this request:
 74:     # * initialize the trace entry for this request
 75:     # * initialize the session identifier for this request
 76:     initialize_trace(request.env)
 77: 
 78: 
 79:     # Configure the index of cache data.
 80:     ApplicationCache::initialize_index
 81: 
 82: 
 83:     # Process this URL request, if the application is active.
 84:     if (APPLICATION_ACTIVE)
 85:       # Obtain the project object.
 86:       project = Project.get(request.env.merge(params))
 87: 
 88: 
 89:       # Host specific preprocessing rules.
 90:       redirect_url = FALSE
 91:       if (load_project_library(project.host.id, URL_PREPROCESS_LIB))
 92:         method_name = 'get_redirect_url_' + project.host.id.to_s
 93:         begin
 94:           eval "redirect_url = #{method_name}(params, request.env)"
 95:         rescue
 96:           l(m(11, method_name))
 97:         end
 98:       end
 99: 
100: 
101:       # The requested URL is deprecated and has a new location.
102:       if (redirect_url)
103:         redirect_to redirect_url
104:       # This is a content item download request.
105:       elsif (is_download(request.env['PATH_INFO']))
106:         if (file = ContentController.get_download_file(project, params))
107:           response.headers['Cache-Control'] = 'must-revalidate'
108:           # Files are sent in chunks of 4096 bytes.
109:           send_file(file,
110:                     :disposition => 'attachment',
111:                     :type        => 'application/force-download')
112:         # The requested item is not available for download, so send the client 
113:         # to the item's view page.
114:         else
115:           redirect_to generate_content_url(params['content_type_name'], 
116:                                            'id',
117:                                            params['content_item_id'])
118:         end
119: 
120:       # This is a project page request.
121:       else
122:         # Instantiate an object for the requested project page.
123:         project.host.page.template = TemplateController.create
124: 
125:         # Determine if this is a printable page.
126:         if (params.keys.has('print'))
127:           printer_friendly = TRUE
128:         else
129:           printer_friendly = FALSE
130:         end
131: 
132:         # Construct the project page for the current request.
133:         project.host.page.template.get(project.host, 
134:                                        build_start, 
135:                                        printer_friendly)
136:         
137:         # Include expires information in the response.
138:         response.headers['Expires'] = Time.now.httpdate
139: 
140:         # Include last modified information in the response.
141:         if ($cache['modified'].has_key?(project.host.name))
142:           modified = $cache['modified'][project.host.name]
143:         else
144:           # The requested page is not cached, and so the project object 
145:           # contains complete data about this page.
146:           if (project.host.page.template.host_last_modified)
147:             modified = project.host.page.template.host_last_modified.httpdate
148:           # The project object does not contain last modified information.
149:           else
150:             modified = ProjectController::last_modified(project.id, 
151:                                         project.host.id,
152:                                         project.host.updated_on,
153:                                         project.host.page.updated_on).httpdate
154:           end
155: 
156:           # Cache the last modified information.
157:           $cache['modified'][project.host.name] = modified
158:         end
159: 
160:         response.headers['Last-Modified'] = modified
161: 
162:         # Configure the appropriate content type header.
163:         response.headers['Content-Type'] = project.host.page.http_content_type
164: 
165:         # Display the project page.
166:         render :inline => project.host.page.template.output
167:       end
168: 
169:     # If the application is not active then display the static maintenance page.
170:     else
171:       render :inline => file_read(MAINTENANCE_TEMPLATE)
172:     end
173:   end

[Validate]