Module: Vanity::Rails::Dashboard

Includes:
AddParticipant
Defined in:
lib/vanity/frameworks/rails.rb

Overview

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

Instance Method Summary collapse

Methods included from AddParticipant

#add_participant

Instance Method Details

#choosesObject



388
389
390
391
392
# File 'lib/vanity/frameworks/rails.rb', line 388

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

#completeObject



362
363
364
365
366
367
368
369
370
371
372
373
374
# File 'lib/vanity/frameworks/rails.rb', line 362

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

#disableObject



376
377
378
379
380
# File 'lib/vanity/frameworks/rails.rb', line 376

def disable
  exp = Vanity.playground.experiment(params[:e].to_sym)
  exp.enabled = false
  render :file=>Vanity.template("_experiment"), :locals=>{:experiment=>exp}
end

#enableObject



382
383
384
385
386
# File 'lib/vanity/frameworks/rails.rb', line 382

def enable
  exp = Vanity.playground.experiment(params[:e].to_sym)
  exp.enabled = true
  render :file=>Vanity.template("_experiment"), :locals=>{:experiment=>exp}
end

#indexObject



350
351
352
353
354
355
356
# File 'lib/vanity/frameworks/rails.rb', line 350

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

#participantObject



358
359
360
# File 'lib/vanity/frameworks/rails.rb', line 358

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

#resetObject



394
395
396
397
398
399
# File 'lib/vanity/frameworks/rails.rb', line 394

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