0

Is there a way I can switch between to views at random for the root path?

root :to => 'pages#blue' or root :to => 'pages#red'

Thanks for any kind of help with this.

Big_Bird
  • 427
  • 8
  • 21
  • You can consider using some a/b testing gem. https://www.ruby-toolbox.com/categories/A_B_Testing – rubish May 18 '12 at 23:15
  • First of all thanks for the answer. I took a look at ABingo today, but seems like the existing solutions focus more on testing copy/text within the view rather that messing with the routes. – Big_Bird May 19 '12 at 15:59

1 Answers1

1

You can pass a lambda as the value of :to, so theoretically you could return two different responses randomly. It might be a better idea to swap the layout/view that's rendered though.

Edit

root to: lambda {|env| [ 302, {'Location'=> your_randomizing_code_here }, [] ]}

You could do that, or something very similar in your controller:

class YourRootController < ActionController::Base
  def index
    render some_method_that_returns_your_view_paths_randomly
  end
end
dogenpunk
  • 4,332
  • 1
  • 21
  • 29
  • Thanks for the answer, would yo kind enough to provide an example how a function like that would look like. Since I understand what needs to be done, but have no idea how to lay it out. – Big_Bird May 19 '12 at 16:01