Class: Plug::FeaturesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/plug/features_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /features



26
27
28
29
30
31
32
33
34
# File 'app/controllers/plug/features_controller.rb', line 26

def create
  @feature = Feature.new(feature_params)

  if @feature.save
    redirect_to features_path, notice: 'Feature was successfully created.'
  else
    render :new
  end
end

#destroyObject

DELETE /features/1



46
47
48
49
# File 'app/controllers/plug/features_controller.rb', line 46

def destroy
  @feature.destroy
  redirect_to features_url, notice: 'Feature was successfully destroyed.'
end

#editObject

GET /features/1/edit



23
# File 'app/controllers/plug/features_controller.rb', line 23

def edit; end

#indexObject

GET /features



10
11
12
# File 'app/controllers/plug/features_controller.rb', line 10

def index
  @features = Feature.all
end

#newObject

GET /features/new



18
19
20
# File 'app/controllers/plug/features_controller.rb', line 18

def new
  @feature = Feature.new
end

#task_executionObject

POST /task TODO: Move this to a separate controller e.g. ‘tasks_controller.rb`



53
54
55
56
57
58
59
60
61
62
63
# File 'app/controllers/plug/features_controller.rb', line 53

def task_execution
  begin
    Plug::TaskExecutionService.new(name: params[:task]).call
  rescue StandardError => e
    flash[:alert] = e.message
  else
    flash[:notice] = "Task: #{params[:task]} has completed"
  end

  redirect_to root_path
end

#updateObject

PATCH/PUT /features/1



37
38
39
40
41
42
43
# File 'app/controllers/plug/features_controller.rb', line 37

def update
  if @feature.update(feature_params)
    redirect_to features_path, notice: 'Feature was successfully updated.'
  else
    render :edit
  end
end