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



401
402
403
404
405
406
# File 'lib/vanity/frameworks/rails.rb', line 401

def chooses
  set_vanity_view_path
  exp = Vanity.playground.experiment(params[:e].to_sym)
  exp.chooses(exp.alternatives[params[:a].to_i].value)
  render template: "_experiment", locals: { experiment: exp }
end

#completeObject



372
373
374
375
376
377
378
379
380
381
382
383
384
385
# File 'lib/vanity/frameworks/rails.rb', line 372

def complete
  set_vanity_view_path
  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 template: "_experiment", locals: { experiment: exp }
  else
    @to_confirm = alt.id
    render template: "_experiment", locals: { experiment: exp }
  end
end

#disableObject



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

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

#enableObject



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

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

#indexObject



358
359
360
361
362
363
364
365
# File 'lib/vanity/frameworks/rails.rb', line 358

def index
  set_vanity_view_path
  render template: "_report", content_type: Mime[:html], locals: {
    experiments: Vanity.playground.experiments,
    experiments_persisted: Vanity.playground.experiments_persisted?,
    metrics: Vanity.playground.metrics,
  }
end

#participantObject



367
368
369
370
# File 'lib/vanity/frameworks/rails.rb', line 367

def participant
  set_vanity_view_path
  render template: "_participant", locals: { participant_id: params[:id], participant_info: Vanity.playground.participant_info(params[:id]) }, content_type: Mime[:html]
end

#resetObject



408
409
410
411
412
413
414
# File 'lib/vanity/frameworks/rails.rb', line 408

def reset
  set_vanity_view_path
  exp = Vanity.playground.experiment(params[:e].to_sym)
  exp.reset
  flash[:notice] = I18n.t 'vanity.experiment_has_been_reset', name: exp.name
  render template: "_experiment", locals: { experiment: exp }
end

#set_vanity_view_pathObject



354
355
356
# File 'lib/vanity/frameworks/rails.rb', line 354

def set_vanity_view_path
  prepend_view_path Vanity.template('')
end