0
@@ -5,6 +5,7 @@ module Ardes #:nodoc:
0
alias_method_chain :default_render, :response_for
0
+ alias_method_chain :template_exists?, :response_for
0
@@ -55,7 +56,7 @@ module Ardes #:nodoc:
0
# response_for :update do |format| # this example is for a resources_controller controller
0
# if !(resource.new_record? || resource.changed?) # => resource.saved?
0
- # format.js { render(:update) {|page| page.replace
(dom_id(resource), :partial => resource}}
0
+ # format.js { render(:update) {|page| page.replace
dom_id(resource), :partial => resource }}
0
# format.js { render(:update) {|page| page.visual_effect :shake, dom_id(resource) }}
0
@@ -63,13 +64,13 @@ module Ardes #:nodoc:
0
- # * If the before_filters or action renders or redirects, then response_for will not be invoked
0
+ # * If the before_filters or action renders or redirects, then response_for will not be invoked
.0
# * you can stack up multiple response_for calls, the most recent has precedence
0
# * the specifed block is executed within the controller instance, so you can use controller
0
# instance methods and instance variables (i.e. you can make it look just like a regular
0
- # * you can add a response_for an action that is just a public template (where there is no
0
- # actual action method defined)
0
+ # * you can add a response_for an action that has no action method defined. This is just like
0
+ # defining a template for an action that has no action method defined.
0
# * you can combine the :types option with a block, the block has precedence if you specify the
0
# same mime type in both.
0
def response_for(*actions, &block)
0
@@ -84,10 +85,6 @@ module Ardes #:nodoc:
0
action_responses[action] ||= []
0
action_responses[action].unshift types_block if types_block
0
action_responses[action].unshift block if block
0
- # if there's no action yet defined, create an empty one - this is so that you
0
- # we may provide responses for templates
0
- class_eval "def #{action}; end" unless instance_methods.include?(action)
0
@@ -113,6 +110,17 @@ module Ardes #:nodoc:
0
+ # does a response exist for the current action?
0
+ self.class.action_responses.keys.include?(action_name.to_s)
0
+ # we extend template_exists? to return true if a template OR a response exists corresponding to the current action.
0
+ # This is so that a default render will be triggered when no action, but a repsonse does exist.
0
+ def template_exists_with_response_for?
0
+ response_exists? || template_exists_without_response_for?
0
# if there are responses for the current action, then respond_to them
0
# we rescue the case where there were no responses, so that the default_render