Class: ActionController::Base

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

Instance Method Summary collapse

Instance Method Details

#respond_with(*resources, &block) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/spree/core/respond_with.rb', line 3

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 response = retrieve_response_from_mimes(&block)
    options = resources.size == 1 ? {} : resources.extract_options!
    options.merge!(:default_response => response)

    # following statement is not present in rails code. 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
    (options.delete(:responder) || Spree::Responder).call(self, resources, options)
  end
end