Module: Exposure::Responding::ClassMethods
- Defined in:
- lib/exposure/behaviors/responding.rb
Instance Method Summary collapse
-
#build_custom_response(action_names, success_status, formats, response) ⇒ Object
:nodoc:.
-
#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.
Instance Method Details
#build_custom_response(action_names, success_status, formats, response) ⇒ Object
:nodoc:
42 43 44 45 46 47 48 |
# File 'lib/exposure/behaviors/responding.rb', line 42 def build_custom_response(action_names, success_status, formats, response) #:nodoc: action_names.each do |action_name| formats.each do |format| self.const_get(:Responses)["#{action_name}.#{success_status}.#{format}"] = response end end end |
#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) = actions. [:is] ||= block formats = [:formats] || [:html] case [:on] when NilClass, :any build_custom_response(actions, :success, formats, [:is]) build_custom_response(actions, :failure, formats, [:is]) when :success build_custom_response(actions, :success, formats, [:is]) when :failure build_custom_response(actions, :failure, formats, [:is]) end end |