Module: Ajax::ActionController::MirrorMethods

Defined in:
lib/ajax/action_controller.rb

Instance Method Summary collapse

Instance Method Details

#ajax_header(*args, &block) ⇒ Object

Set a custom response header if the request is AJAX.

Call with key and optional value. Pass a block to yield a dynamic value.

Accepts :only and :except conditions because we create an after_filter.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ajax/action_controller.rb', line 21

def ajax_header(*args, &block)
  return unless Ajax.is_enabled?

  options = args.extract_options!
  key, value = args.shift, args.shift
  value = block_given? ? Proc.new : value

  (self.is_a?(Class) ? self : self.class).prepend_after_filter(options) do |controller|
    if controller.request.xhr?
      value = value.is_a?(Proc) ? controller.instance_eval(&value) : value
      Ajax.set_header(controller.response, key, value)
    end
  end
end

#ajax_layout(template_name) ⇒ Object

Set the layout to use for AJAX requests.

By default we look in layouts/ajax/ for this controllers default layout and render that. If it can’t be found, the default layout is used.



41
42
43
# File 'lib/ajax/action_controller.rb', line 41

def ajax_layout(template_name)
  (self.is_a?(Class) ? self : self.class).write_inheritable_attribute(:ajax_layout, template_name)
end