Method: Exposure::Responding::ClassMethods#response_for

Defined in:
lib/exposure/behaviors/responding.rb

#response_for(*actions, &block) ⇒ Object

response_for :create, :on => :success, :is => { proc } response_for :show, :formats => [:html] do

@resource.activated ? render('show') : render('next_steps')

end response_for :new, :is => :new_foo_built

valid action names are

:index :show :new :create :edit :update :destroy

valid options are

:on (optional)
  :success, :failure, :any
  default is :any
:is (option if block given)
  can be a Proc or method name as symbol.
:formats
  array of formats as symbols.
  defaults to [:html]


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/exposure/behaviors/responding.rb', line 26

def response_for(*actions, &block)
  options = actions.extract_options!
  options[:is] ||= block
  formats  = options[:formats] || [:html, :xml, :json]
  
  case options[:on]
  when NilClass, :any
    build_custom_response(actions, :success, formats, options[:is])
    build_custom_response(actions, :failure, formats, options[:is])
  when :success
    build_custom_response(actions, :success, formats, options[:is])
  when :failure
    build_custom_response(actions, :failure, formats, options[:is])
  end
end