Skip to content

Commit 6bc84fa

Browse files
Implement a first experiment
This sets up a simple UI experiment, defining an alternative set of styles for the search form. The search form starts in the _form.html.erb partial, with most users getting a "standard" class - the experimental group would get the "alt" class, which is rendered differently. The experiment ends when a user reaches a search results page (i.e, they submitted the form and thus got results). Curious folks can force themselves into one or the other pool by using a querystring such as ?ab_test[ui_colors]=alt or ?ab_test[ui_colors]=standard
1 parent 760ffff commit 6bc84fa

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

app/assets/stylesheets/partials/_search.scss

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@
44

55
/* basic search bar */
66
.basic-search {
7-
background-color: #989898;
7+
8+
&.standard {
9+
background-color: #989898;
10+
}
11+
12+
&.alt {
13+
background-color: #ffd700;
14+
}
15+
816
margin-bottom: 1rem;
917
padding: 1.6rem 2rem;
1018

app/controllers/search_controller.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ class SearchController < ApplicationController
22
before_action :validate_q!, only: %i[results]
33

44
def results
5+
# if we are loading results, the user submitted the form - so this experiment is finished
6+
ab_finished(:ui_colors)
7+
58
# hand off to Enhancer chain
69
@enhanced_query = Enhancer.new(params).enhanced_query
710

app/views/search/_form.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ end
1717

1818
%>
1919

20-
<form id="basic-search" class="form-horizontal basic-search" action="<%= results_path %>" method="get">
20+
<form id="basic-search" class="form-horizontal basic-search <%= ab_test(:ui_colors, "standard", "alt") %>" action="<%= results_path %>" method="get">
2121
<div class="form-group">
2222
<label for="basic-search-main" class="field-label"><%= label %></label>
2323
<input id="basic-search-main" type="search" class="field field-text basic-search-input <%= "required" if search_required %>" name="q" placeholder="Enter your search" value="<%= params[:q] %>" <%= 'required="required" aria-required="true"' if search_required %>>

0 commit comments

Comments
 (0)