formats=

formats=(extensions)
Instance Public methods

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 fallback to the :html format.

1
2
3
4
5
6
7
8
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
doc_ruby_on_rails
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.