Module: Motr::Controller::Helpers

Extended by:
ActiveSupport::Concern
Defined in:
lib/motr/controller/helpers.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#generate_ajax_headersObject

Generates additional header information for ajax requests, to allow more flexibility in handling responses. It simply creates a X-Response-Meta header in the response which contains a json object representing the requested controller and action name, as well as any user defined metadata set with add_response_meta

See Also:

  • Motr#Controller#Helpers#add_response_meta


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/motr/controller/helpers.rb', line 23

def generate_ajax_headers  #:nodoc:
  return true unless response.content_type.to_s.match(/javascript/i)
  
  response_params = request.filtered_parameters.dup
  controller_name = response_params.delete('controller').to_s.underscore
  action_name     = response_params.delete('action').to_s
  
  parsed_meta = self.class.
  parsed_meta = case parsed_meta
    when Symbol then send(parsed_meta)
    when Proc   then parsed_meta.call
    else parsed_meta
  end
  
  meta_info       = {
    :pathinfo => "#{controller_name}##{action_name}",
    :meta     => parsed_meta
  }
  response.header['X-Response-Meta'] = meta_info.to_json
  
end