Class: ActionController::Base
- Inherits:
-
Object
- Object
- ActionController::Base
- Defined in:
- lib/vendor/plugins/inherited_resources/lib/inherited_resources/legacy/respond_to.rb,
lib/vendor/plugins/inherited_resources/lib/inherited_resources.rb
Overview
:nodoc:
Direct Known Subclasses
Instance Attribute Summary collapse
-
#formats ⇒ Object
Returns the value of attribute formats.
Class Method Summary collapse
-
.clear_respond_to ⇒ Object
Clear all mimes in respond_to.
-
.inherit_resources ⇒ Object
If you cannot inherit from InheritedResources::Base you can call inherit_resource in your controller to have all the required modules and funcionality included.
-
.respond_to(*mimes) ⇒ Object
Defines mimes that are rendered by default when invoking respond_with.
Instance Method Summary collapse
Instance Attribute Details
#formats ⇒ Object
Returns the value of attribute formats.
3 4 5 |
# File 'lib/vendor/plugins/inherited_resources/lib/inherited_resources/legacy/respond_to.rb', line 3 def formats @formats end |
Class Method Details
.clear_respond_to ⇒ Object
Clear all mimes in respond_to.
42 43 44 |
# File 'lib/vendor/plugins/inherited_resources/lib/inherited_resources/legacy/respond_to.rb', line 42 def self.clear_respond_to write_inheritable_attribute(:mimes_for_respond_to, ActiveSupport::OrderedHash.new) end |
.inherit_resources ⇒ Object
If you cannot inherit from InheritedResources::Base you can call inherit_resource in your controller to have all the required modules and funcionality included.
18 19 20 21 22 |
# File 'lib/vendor/plugins/inherited_resources/lib/inherited_resources.rb', line 18 def self.inherit_resources InheritedResources::Base.inherit_resources(self) initialize_resources_class_accessors! create_resources_url_helpers! end |
.respond_to(*mimes) ⇒ Object
Defines mimes that are rendered by default when invoking respond_with.
Examples:
respond_to :html, :xml, :json
All actions on your controller will respond to :html, :xml and :json.
But if you want to specify it based on your actions, you can use only and except:
respond_to :html
respond_to :xml, :json, :except => [ :edit ]
The definition above explicits that all actions respond to :html. And all actions except :edit respond to :xml and :json.
You can specify also only parameters:
respond_to :rjs, :only => :create
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/vendor/plugins/inherited_resources/lib/inherited_resources/legacy/respond_to.rb', line 26 def self.respond_to(*mimes) = mimes. only_actions = Array(.delete(:only)) except_actions = Array(.delete(:except)) mimes.each do |mime| mime = mime.to_sym mimes_for_respond_to[mime] = {} mimes_for_respond_to[mime][:only] = only_actions unless only_actions.empty? mimes_for_respond_to[mime][:except] = except_actions unless except_actions.empty? end end |
Instance Method Details
#respond_to(*mimes, &block) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/vendor/plugins/inherited_resources/lib/inherited_resources/legacy/respond_to.rb', line 54 def respond_to(*mimes, &block) raise ArgumentError, "respond_to takes either types or a block, never both" if mimes.any? && block_given? if response = retrieve_response_from_mimes(mimes, &block) response.call end end |
#respond_with(*resources, &block) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/vendor/plugins/inherited_resources/lib/inherited_resources/legacy/respond_to.rb', line 61 def respond_with(*resources, &block) if response = retrieve_response_from_mimes([], &block) = resources. .merge!(:default_response => response) (.delete(:responder) || responder).call(self, resources, ) end end |
#responder ⇒ Object
69 70 71 |
# File 'lib/vendor/plugins/inherited_resources/lib/inherited_resources/legacy/respond_to.rb', line 69 def responder ActionController::Responder end |