module Vanity::Rails::Dashboard

Step 1: Add a new resource in config/routes.rb:

map.vanity "/vanity/:action/:id", :controller=>:vanity

Step 2: Create a new experiments controller:

class VanityController < ApplicationController
  include Vanity::Rails::Dashboard
end

Step 3: Open your browser to localhost:3000/vanity

Public Instance Methods

chooses() click to toggle source
# File lib/vanity/frameworks/rails.rb, line 389
def chooses
  exp = Vanity.playground.experiment(params[:e].to_sym)
  exp.chooses(exp.alternatives[params[:a].to_i].value)
  render :file=>Vanity.template("_experiment"), :locals=>{:experiment=>exp}
end
complete() click to toggle source
# File lib/vanity/frameworks/rails.rb, line 363
def complete
  exp = Vanity.playground.experiment(params[:e].to_sym)
  alt = exp.alternatives[params[:a].to_i]
  confirmed = params[:confirmed]
  # make the user confirm before completing an experiment
  if confirmed && confirmed.to_i==alt.id && exp.active?
    exp.complete!(alt.id)
    render :file=>Vanity.template("_experiment"), :locals=>{:experiment=>exp}
  else
    @to_confirm = alt.id
    render :file=>Vanity.template("_experiment"), :locals=>{:experiment=>exp}
  end
end
disable() click to toggle source
# File lib/vanity/frameworks/rails.rb, line 377
def disable
  exp = Vanity.playground.experiment(params[:e].to_sym)
  exp.enabled = false
  render :file=>Vanity.template("_experiment"), :locals=>{:experiment=>exp}
end
enable() click to toggle source
# File lib/vanity/frameworks/rails.rb, line 383
def enable
  exp = Vanity.playground.experiment(params[:e].to_sym)
  exp.enabled = true
  render :file=>Vanity.template("_experiment"), :locals=>{:experiment=>exp}
end
index() click to toggle source
# File lib/vanity/frameworks/rails.rb, line 351
def index
  render :file=>Vanity.template("_report"),:content_type=>Mime[:html], :locals=>{
    :experiments=>Vanity.playground.experiments,
    :experiments_persisted=>Vanity.playground.experiments_persisted?,
    :metrics=>Vanity.playground.metrics
  }
end
participant() click to toggle source
# File lib/vanity/frameworks/rails.rb, line 359
def participant
  render :file=>Vanity.template("_participant"), :locals=>{:participant_id => params[:id], :participant_info => Vanity.playground.participant_info(params[:id])}, :content_type=>Mime[:html]
end
reset() click to toggle source
# File lib/vanity/frameworks/rails.rb, line 395
def reset
  exp = Vanity.playground.experiment(params[:e].to_sym)
  exp.reset
  flash[:notice] = I18n.t 'vanity.experiment_has_been_reset', name: exp.name
  render :file=>Vanity.template("_experiment"), :locals=>{:experiment=>exp}
end