Class: ActionController::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/spree/core/controller_helpers/respond_with.rb

Instance Method Summary collapse

Instance Method Details

#respond_with(*resources, &block) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/spree/core/controller_helpers/respond_with.rb', line 5

def respond_with(*resources, &block)
  raise "In order to use respond_with, first you need to declare the formats your " <<
        "controller responds to in the class level" if self.class.mimes_for_respond_to.empty?

  if collector = retrieve_collector_from_mimes(&block)
    options = resources.size == 1 ? {} : resources.extract_options!

    if defined_response = collector.response and !Spree::BaseController.spree_responders.keys.include?(self.class.to_s.to_sym)
      if action = options.delete(:action)
        render :action => action
      else
        defined_response.call
      end
    else
      # The action name is needed for processing
      options.merge!(:action_name => action_name.to_sym)
      # If responder is not specified then pass in Spree::Responder
      responder = options.delete(:responder) || self.responder
      responder.call(self, resources, options)
    end
  end
end