Fixing No Default Alternative Specified error in rails

If you spot an error saying No default alternative specified when starting up rails, we can fix that!

If when you start up Rails locally you see the message;

  No default alternative specified; choosing `x` as default

Then this means you probably have the Vanity Gem installed in your project.

This is an A/B testing gem, and the error is basically saying that in one of your experiments you have not specified a default. When this happens the first of the alternatives is picked.

For example; if you had the following in an experiement file;

  ab_test 'My AB Test' do
    description 'Sample Test'
    alternatives 'First', 'Second', 'Third'
    metrics :my_metric
  end

I would expect you to get an error on startup of your Rails server saying;

  No default alternative specified; choosing First as default

In order to fix this we simply need to specify a default

  ab_test 'My AB Test' do
    description 'Sample Test'
    alternatives 'First', 'Second', 'Third'
    metrics :my_metric
    default 'Third'
  end

Recent posts View all

Talk CSS

FrontEnders - Web Performance

Sharing some of my thoughts on a FrontEnders meetup on the topic of Web Performance

Conferences

Tips for how to ask for time off to attend conferences

Asking for time off to attend a conference can be nerve-racking, these tips will get you closer to attending the conferences you're interested in.