Created
August 8, 2016 11:42
-
-
Save brenes/86cee6037b860bb3aad903adbc5877ea to your computer and use it in GitHub Desktop.
Revisions
-
brenes created this gist
Aug 8, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ # This code is an example to combine different variants from different reasons into the request.variant setting from Rails 4.1 before_action :set_versions def set_versions # First, we load all the variants from whatever our variant logic is (mobile support, tests ab, beta versions...) variants = [] variants << params[:b].to_sym if params[:b] variants << params[:a].to_sym if params[:a] # Now, we combine the variants combined_variants = [] variants.length.times do |i| combined_variants << variants.combination(i+1).to_a end combined_variants = combined_variants.reverse.flatten(1) combined_variants = combined_variants.map{|v| v.join("+").to_sym} # and assign the request.variant request.variant = combined_variants end