Class: Subflag::Rails::FlagsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Subflag::Rails::FlagsController
- Defined in:
- app/controllers/subflag/rails/flags_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #test ⇒ Object
- #toggle ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'app/controllers/subflag/rails/flags_controller.rb', line 18 def create @flag = Flag.new(flag_params) if @flag.save redirect_to flags_path, notice: "Flag created." else render :new, status: :unprocessable_entity end end |
#destroy ⇒ Object
37 38 39 40 |
# File 'app/controllers/subflag/rails/flags_controller.rb', line 37 def destroy @flag.destroy redirect_to flags_path, notice: "Flag deleted." end |
#edit ⇒ Object
27 |
# File 'app/controllers/subflag/rails/flags_controller.rb', line 27 def edit; end |
#index ⇒ Object
8 9 10 |
# File 'app/controllers/subflag/rails/flags_controller.rb', line 8 def index @flags = Flag.order(:key) end |
#new ⇒ Object
14 15 16 |
# File 'app/controllers/subflag/rails/flags_controller.rb', line 14 def new @flag = Flag.new(enabled: true, value_type: "boolean", value: "false") end |
#show ⇒ Object
12 |
# File 'app/controllers/subflag/rails/flags_controller.rb', line 12 def show; end |
#test ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'app/controllers/subflag/rails/flags_controller.rb', line 47 def test context = parse_test_context(params[:context]) @test_result = @flag.evaluate(context: context) @test_context = context respond_to do |format| format.html { render :edit } format.json { render json: { result: @test_result, context: @test_context } } end end |
#toggle ⇒ Object
42 43 44 45 |
# File 'app/controllers/subflag/rails/flags_controller.rb', line 42 def toggle @flag.update!(enabled: !@flag.enabled) redirect_to flags_path, notice: "Flag #{@flag.enabled? ? 'enabled' : 'disabled'}." end |
#update ⇒ Object
29 30 31 32 33 34 35 |
# File 'app/controllers/subflag/rails/flags_controller.rb', line 29 def update if @flag.update(flag_params) redirect_to edit_flag_path(@flag), notice: "Flag updated." else render :edit, status: :unprocessable_entity end end |