diff options
author | Lukasz Strzalkowski <lukaszstrzalkowski@squareup.com> | 2014-02-13 15:59:09 +0100 |
---|---|---|
committer | Lukasz Strzalkowski <lukaszstrzalkowski@squareup.com> | 2014-02-13 16:22:56 +0100 |
commit | f9b6b865e60ea770cc34e9946f6df1604f20dd27 (patch) | |
tree | 552d0ab1ade45463bf5acdfe53a7ac6944806cbe /actionpack/lib/action_dispatch | |
parent | de5ef153984f4fc3229a3346a8a4a1595303afc8 (diff) | |
download | rails-f9b6b865e60ea770cc34e9946f6df1604f20dd27.tar.gz rails-f9b6b865e60ea770cc34e9946f6df1604f20dd27.tar.bz2 rails-f9b6b865e60ea770cc34e9946f6df1604f20dd27.zip |
Variant negotiation
Allow setting `request.variant` as an array - an order in which they will be
rendered.
For example:
request.variant = [:tablet, :phone]
respond_to do |format|
format.html.none
format.html.phone # this gets rendered
end
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r-- | actionpack/lib/action_dispatch/http/mime_negotiation.rb | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/actionpack/lib/action_dispatch/http/mime_negotiation.rb b/actionpack/lib/action_dispatch/http/mime_negotiation.rb index c33ba201e1..b75d7ffe9d 100644 --- a/actionpack/lib/action_dispatch/http/mime_negotiation.rb +++ b/actionpack/lib/action_dispatch/http/mime_negotiation.rb @@ -68,10 +68,12 @@ module ActionDispatch # Sets the \variant for template. def variant=(variant) - if variant.is_a? Symbol + if variant.is_a?(Symbol) + @variant = [variant] + elsif variant.is_a?(Array) @variant = variant else - raise ArgumentError, "request.variant must be set to a Symbol, not a #{variant.class}. " \ + raise ArgumentError, "request.variant must be set to a Symbol or Array, not a #{variant.class}. " \ "For security reasons, never directly set the variant to a user-provided value, " \ "like params[:variant].to_sym. Check user-provided value against a whitelist first, " \ "then set the variant: request.variant = :tablet if params[:variant] == 'tablet'" |