Module: Experimental::ControllerActions

Extended by:
ActiveSupport::Concern
Defined in:
lib/experimental/controller_actions.rb

Instance Method Summary collapse

Instance Method Details

#base_resource_nameObject



17
18
19
# File 'lib/experimental/controller_actions.rb', line 17

def base_resource_name
  @base_resource_name ||= "experiment"
end

#createObject



68
69
70
71
72
73
74
# File 'lib/experimental/controller_actions.rb', line 68

def create
  if experiments_create
    redirect_to experimental_path_names.index
  else
    render :new
  end
end

#experimental_path_namesObject



33
34
35
36
# File 'lib/experimental/controller_actions.rb', line 33

def experimental_path_names
  set_experimental_path_names if @experimental_path_names.nil?
  @experimental_path_names
end

#experiments_createObject



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/experimental/controller_actions.rb', line 48

def experiments_create
  @experiment = Experiment.new(params[:experimental_experiment])
  @experiment.admin = true
  @experiment.start_date = Time.now

  if @experiment.save
    flash[:notice] = "Experiment was successfully created."
    return true
  else
    flash.now[:error] = "There was an error!"
    return false
  end
end

#experiments_inactiveObject



62
63
64
65
66
# File 'lib/experimental/controller_actions.rb', line 62

def experiments_inactive
  @h1 = "Ended or Removed Experiments"
  @include_inactive = true
  @experiments = Experiment.ended_or_removed
end

#experiments_indexObject



38
39
40
41
42
# File 'lib/experimental/controller_actions.rb', line 38

def experiments_index
  @h1 = "In-progress Experiments"
  @include_inactive = false
  @experiments = Experiment.in_progress
end

#experiments_newObject



44
45
46
# File 'lib/experimental/controller_actions.rb', line 44

def experiments_new
  @experiment = Experiment.new
end

#experiments_set_winnerObject



81
82
83
84
85
86
87
88
# File 'lib/experimental/controller_actions.rb', line 81

def experiments_set_winner
  exp = Experiment.find params[:id]
  if exp.end(params[:bucket_id])
    render json: nil, status: :ok
  else
    render json: nil, status: :error
  end
end

#inactiveObject



76
77
78
79
# File 'lib/experimental/controller_actions.rb', line 76

def inactive
  experiments_inactive
  render :index
end

#set_experimental_path_namesObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/experimental/controller_actions.rb', line 21

def set_experimental_path_names
  @experimental_path_names = OpenStruct.new
  plural_path = "#{base_resource_name.pluralize}_path"

  @experimental_path_names.index = self.send(plural_path.to_sym)
  if self.respond_to?("inactive_#{plural_path}".to_sym)
    @experimental_path_names.inactive = self.send("inactive_#{plural_path}".to_sym)
  end
  @experimental_path_names.new = self.send("new_#{base_resource_name}_path".to_sym)
  @experimental_path_names.set_winner = self.send("set_winner_#{plural_path}".to_sym)
end