instance method
formats=
Ruby on Rails 7.0.10
Since v4.0.13Signature
formats=(extensions)
Sets the \formats by string extensions. This differs from #format= by allowing you to set multiple, ordered formats, which is useful when you want to have a fallback.
In this example, the :iphone format will be used if it’s available, otherwise it’ll fall back to the :html format.
class ApplicationController < ActionController::Base before_action :adjust_format_for_iphone_with_html_fallback private def adjust_format_for_iphone_with_html_fallback request.formats = [ :iphone, :html ] if request.env["HTTP_USER_AGENT"][/iPhone/] end end
Parameters
-
extensionsreq
Source
# File actionpack/lib/action_dispatch/http/mime_negotiation.rb, line 146
def formats=(extensions)
parameters[:format] = extensions.first.to_s
set_header "action_dispatch.request.formats", extensions.collect { |extension|
Mime::Type.lookup_by_extension(extension)
}
end
Defined in actionpack/lib/action_dispatch/http/mime_negotiation.rb line 146
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActionDispatch::Http::MimeNegotiation