Class: RailsOnboarding::AbTestsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- RailsOnboarding::AbTestsController
- Includes:
- AdminAuthorization, RateLimitable
- Defined in:
- app/controllers/rails_onboarding/ab_tests_controller.rb
Overview
Controller for managing A/B tests and viewing results Provides endpoints for test management and analytics
Instance Method Summary collapse
-
#assign_variant ⇒ Object
POST /ab_tests/:test_name/assign_variant Manually assign a user to a specific variant.
-
#index ⇒ Object
GET /ab_tests List all configured A/B tests.
-
#results ⇒ Object
GET /ab_tests/:test_name/results View results and analytics for an A/B test.
-
#show ⇒ Object
GET /ab_tests/:test_name Show details for a specific A/B test.
-
#toggle ⇒ Object
POST /ab_tests/:test_name/toggle Enable or disable an A/B test.
Instance Method Details
#assign_variant ⇒ Object
POST /ab_tests/:test_name/assign_variant Manually assign a user to a specific variant
72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'app/controllers/rails_onboarding/ab_tests_controller.rb', line 72 def assign_variant user_id = params[:user_id] variant = params[:variant] test_name = params[:test_name] user = user_class.find_by(id: user_id) if user && user.respond_to?(:assign_variant) user.assign_variant(test_name, variant) render json: { success: true, variant: variant } else render json: { success: false, error: "User not found or AbTestable not included" }, status: :unprocessable_entity end end |
#index ⇒ Object
GET /ab_tests List all configured A/B tests
24 25 26 27 28 29 30 31 |
# File 'app/controllers/rails_onboarding/ab_tests_controller.rb', line 24 def index @ab_tests = RailsOnboarding.configuration.ab_tests || {} respond_to do |format| format.html format.json { render json: @ab_tests } end end |
#results ⇒ Object
GET /ab_tests/:test_name/results View results and analytics for an A/B test
44 45 46 47 48 49 50 51 52 |
# File 'app/controllers/rails_onboarding/ab_tests_controller.rb', line 44 def results @results = calculate_results @funnel = calculate_funnel_by_variant respond_to do |format| format.html format.json { render json: { results: @results, funnel: @funnel } } end end |
#show ⇒ Object
GET /ab_tests/:test_name Show details for a specific A/B test
35 36 37 38 39 40 |
# File 'app/controllers/rails_onboarding/ab_tests_controller.rb', line 35 def show respond_to do |format| format.html format.json { render json: test_details } end end |
#toggle ⇒ Object
POST /ab_tests/:test_name/toggle Enable or disable an A/B test
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/controllers/rails_onboarding/ab_tests_controller.rb', line 56 def toggle # Note: This modifies runtime configuration, not persistent storage # For production use, configuration should be managed via config files or database current_state = @test_config[:enabled] @test_config[:enabled] = !current_state flash[:notice] = "A/B test #{@test_name} #{@test_config[:enabled] ? 'enabled' : 'disabled'}" respond_to do |format| format.html { redirect_to ab_tests_path } format.json { render json: { enabled: @test_config[:enabled] } } end end |