summaryrefslogtreecommitdiff
path: root/app/controllers/projects/triggers_controller.rb
blob: 92359745cec883d6d9405340a5d9f571243529c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class Projects::TriggersController < Projects::ApplicationController
  before_action :authorize_admin_build!

  layout 'project_settings'

  def index
    @triggers = project.triggers
    @trigger = Ci::Trigger.new
  end

  def create
    @trigger = project.triggers.new
    @trigger.save

    if @trigger.valid?
      redirect_to namespace_project_triggers_path(@project.namespace, @project)
    else
      @triggers = project.triggers.select(&:persisted?)
      render :index
    end
  end

  def destroy
    trigger.destroy

    redirect_to namespace_project_triggers_path(@project.namespace, @project)
  end

  private

  def trigger
    @trigger ||= project.triggers.find(params[:id])
  end
end