Module: ActionController::MimeResponds::ClassMethods
- Defined in:
- lib/respond_with_backport.rb
Instance Method Summary collapse
-
#clear_respond_to ⇒ Object
Clear all mimes in respond_to.
-
#respond_to(*mimes) ⇒ Object
Defines mimes that are rendered by default when invoking respond_with.
Instance Method Details
#clear_respond_to ⇒ Object
Clear all mimes in respond_to.
320 321 322 |
# File 'lib/respond_with_backport.rb', line 320 def clear_respond_to self.mimes_for_respond_to = ActiveSupport::OrderedHash.new 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
304 305 306 307 308 309 310 311 312 313 314 315 316 |
# File 'lib/respond_with_backport.rb', line 304 def 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 |