Can't Install Vanity A/B Testing on Rails

449 views Asked by At

I'm trying to install Vanity A/B Testing in my Rails App, but I can't even get the example from the GitHub page working. I've generated the vanity models and run the migrations and made the experiment files, but as soon as I include a test like

<%= ab_test :price_options %>

the program throws an error:

invalid value for Integer(): "{:conditions=>{:experiment_id=>\"price_options\""

In my controllers/application_controller.rb I have just:

class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception
  use_vanity
end

I didn't include a user identifier because I haven't built one into this app yet, but the Vanity docs say that if no argument is supplied Vanity will just use cookies instead, so that shouldn't be an issue. If anyone has any clue why this cryptic error is being thrown, I would be very appreciative!

Edit: I should add that I actually started a new rails app from scratch just to try and debug this. Literally all I did was start an app and install vanity following the readme instructions and I got this same error. This has happened on two different machines as well, so I suspect it's something obvious that I'm missing, but I can't be sure (else I wouldn't be here!).

EDIT: I've since decided to use the Split gem instead, and am having no troubles with it.

2

There are 2 answers

0
user3752633 On BEST ANSWER

This error is thrown because the current release version of Vanity uses the deprecated Rails find(:first) method, specifically:

 VanityParticipant.first(:conditions=>{ :experiment_id=>experiment.to_s, :identity=>identity.to_s })

This no longer works with Rails 4.1 but is fixed in the master branch of Vanity, so you can get round this in your Rails 4.1 app by adding:

gem 'vanity', :git => '[email protected]:assaf/vanity', :branch => 'master'

to your Gemfile.

1
phillbaker On

With

class ApplicationController < ActionController::Base
  protect_from_forgery
  use_vanity
end

and

# experiments/price_options.rb
ab_test "Price options" do
  description "Mirror, mirror on the wall, who's the best price of all?"
  alternatives(19, 25, 29)
end

and

class StaticController < ApplicationController
  def home
  end
end

the following view loads and sets a vanity_id cookie:

<h1>Static#home</h1>
<p>Find me in app/views/static/home.html.erb</p>

<h2>Get started for only $<%= ab_test :price_options %> a month!</h2>
<%= link_to 'Make a new account', new_account_path %>