Class: FieldTest::ExperimentsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/field_test/experiments_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



3
4
5
# File 'app/controllers/field_test/experiments_controller.rb', line 3

def index
  @active_experiments, @completed_experiments = FieldTest::Experiment.all.sort_by(&:id).partition { |e| e.active? }
end

#showObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/field_test/experiments_controller.rb', line 7

def show
  @experiment = FieldTest::Experiment.find(params[:id])

  @per_page = 200
  @page = [1, params[:page].to_i].max
  offset = (@page - 1) * @per_page
  @memberships = @experiment.memberships.order(created_at: :desc).limit(@per_page).offset(offset).to_a

  @events =
    if FieldTest.events_supported?
      @experiment.events.where(field_test_membership_id: @memberships.map(&:id)).group(:field_test_membership_id, :name).count
    else
      {}
    end
rescue FieldTest::ExperimentNotFound
  raise ActionController::RoutingError, "Experiment not found"
end