aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/http
diff options
context:
space:
mode:
authorTimo Schilling <timo@schilling.io>2014-12-16 11:30:24 +0100
committerTimo Schilling <timo@schilling.io>2014-12-16 11:37:04 +0100
commite1fb3483d6402bd66c41a12d158fd1c987fac983 (patch)
tree0b866c170acfb07f15870f28e81a8f304e0f042c /actionpack/lib/action_dispatch/http
parent41dc7fd650b0fcaf8f05f895aab13febac0739ec (diff)
downloadrails-e1fb3483d6402bd66c41a12d158fd1c987fac983.tar.gz
rails-e1fb3483d6402bd66c41a12d158fd1c987fac983.tar.bz2
rails-e1fb3483d6402bd66c41a12d158fd1c987fac983.zip
allow reseting of request variants
The current implementation of `variants=` don't allow a resetting to nil, wich is the default value. This results in the following code smell: ```ruby case request.user_agent when /iPhone/ request.variants = :phone when /iPad/ request.variants = :ipad end ``` With the ability to reset variants to nil, it could be: ```ruby request.variants = case request.user_agent when /iPhone/ :phone when /iPad/ :ipad end ```
Diffstat (limited to 'actionpack/lib/action_dispatch/http')
-rw-r--r--actionpack/lib/action_dispatch/http/mime_negotiation.rb3
1 files changed, 2 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/http/mime_negotiation.rb b/actionpack/lib/action_dispatch/http/mime_negotiation.rb
index 9c8f65deac..53a98c5d0a 100644
--- a/actionpack/lib/action_dispatch/http/mime_negotiation.rb
+++ b/actionpack/lib/action_dispatch/http/mime_negotiation.rb
@@ -72,11 +72,12 @@ module ActionDispatch
end
end
end
+
# Sets the \variant for template.
def variant=(variant)
if variant.is_a?(Symbol)
@variant = [variant]
- elsif variant.is_a?(Array) && variant.any? && variant.all?{ |v| v.is_a?(Symbol) }
+ elsif variant.nil? || variant.is_a?(Array) && variant.any? && variant.all?{ |v| v.is_a?(Symbol) }
@variant = variant
else
raise ArgumentError, "request.variant must be set to a Symbol or an Array of Symbols, not a #{variant.class}. " \