module Vanity::Rails::AddParticipant
When configuring use_js to true, you must set up a route to add_participant_route.
Step 1: Add a new resource in config/routes.rb:
post "/vanity/add_participant" => "vanity#add_participant"
Step 2: Include Vanity::Rails::AddParticipant
(or Vanity::Rails::Dashboard
) in VanityController
class VanityController < ApplicationController include Vanity::Rails::AddParticipant end
Step 3: Open your browser to localhost:3000/vanity
Public Instance Methods
add_participant()
click to toggle source
JS callback action used by vanity_js
# File lib/vanity/frameworks/rails.rb, line 317 def add_participant if params[:v].nil? head 404 return end h = {} params[:v].split(',').each do |pair| exp_id, answer = pair.split('=') exp = Vanity.playground.experiment(exp_id.to_s.to_sym) rescue nil answer = answer.to_i if !exp || !exp.alternatives[answer] head 404 return end h[exp] = exp.alternatives[answer].value end h.each{ |e,a| e.chooses(a, request) } head 200 end