Class: ActionController::Base
- Inherits:
-
Object
- Object
- ActionController::Base
- Defined in:
- lib/inherited_resources/legacy/respond_to.rb,
lib/inherited_resources.rb
Overview
:nodoc:
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/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/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/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/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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File '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? responder = ActionController::MimeResponds::Responder.new(self) mimes = collect_mimes_from_class_level if mimes.empty? mimes.each { |mime| responder.send(mime) } block.call(responder) if block_given? if format = responder.negotiate_mime self.response.template.template_format = format.to_sym self.response.content_type = format.to_s self.formats = [ format.to_sym ] if response = responder.response_for(format) response.call else default_render end else head :not_acceptable end end |
#respond_with(*resources, &block) ⇒ Object
77 78 79 80 81 82 |
# File 'lib/inherited_resources/legacy/respond_to.rb', line 77 def respond_with(*resources, &block) respond_to(&block) rescue ActionView::MissingTemplate = resources. (.delete(:responder) || responder).call(self, resources, ) end |
#responder ⇒ Object
84 85 86 |
# File 'lib/inherited_resources/legacy/respond_to.rb', line 84 def responder ActionController::Responder end |