Module: ActionDispatch::Http::MimeNegotiation
- Defined in:
- lib/mime_fallback/mime_negotiation.rb
Instance Method Summary collapse
-
#negotiate_mime(order) ⇒ Object
Override to support mime type fallbacks.
Instance Method Details
#negotiate_mime(order) ⇒ Object
Override to support mime type fallbacks
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/mime_fallback/mime_negotiation.rb', line 9 def negotiate_mime(order) # make search easier later responding_formats = order.index_by(&:to_sym) # formats are the request's formats formats.each do |priority| return order.first if priority == Mime::ALL # Try to find an exact match to what we're responding to types = Array(priority) + MimeFallback::Type.fallbacks(priority.to_sym) fallback = types.detect{|type| responding_formats.has_key?(type.to_sym)} return fallback if fallback # we've found an exact match return priority if responding_formats.has_key?(priority.to_sym) end order.include?(Mime::ALL) ? formats.first : nil end |