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



389
390
391
392
393
# 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

#completeObject



363
364
365
366
367
368
369
370
371
372
373
374
375
# 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

#disableObject



377
378
379
380
381
# 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

#enableObject



383
384
385
386
387
# 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

#indexObject



351
352
353
354
355
356
357
# 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

#participantObject



359
360
361
# 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

#resetObject



395
396
397
398
399
400
# 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