Module: ActionController::MimeResponds::ClassMethods

Defined in:
lib/respond_with_backport.rb

Instance Method Summary collapse

Instance Method Details

#clear_respond_toObject

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)
  options = mimes.extract_options!

  only_actions   = Array(options.delete(:only))
  except_actions = Array(options.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