Sha256: 87128aa04d50b9d81ba6afb0655efa294aab86450ef3d4d3474ecb7f4b5c1873

Contents?: true

Size: 1.23 KB

Versions: 6

Compression:

Stored size: 1.23 KB

Contents

module Blazer
  class ChecksController < BaseController
    before_action :set_check, only: [:edit, :update, :destroy, :run]

    def index
      @checks = Blazer::Check.joins(:query).includes(:query).order("state, blazer_queries.name, blazer_checks.id").to_a
      @checks.select! { |c| "#{c.query.name} #{c.emails}".downcase.include?(params[:q]) } if params[:q]
    end

    def new
      @check = Blazer::Check.new
    end

    def create
      @check = Blazer::Check.new(check_params)
      # use creator_id instead of creator
      # since we setup association without checking if column exists
      @check.creator = blazer_user if @check.respond_to?(:creator_id=)

      if @check.save
        redirect_to run_check_path(@check)
      else
        render :new
      end
    end

    def update
      if @check.update(check_params)
        redirect_to run_check_path(@check)
      else
        render :edit
      end
    end

    def destroy
      @check.destroy
      redirect_to checks_path
    end

    def run
      @query = @check.query
    end

    private

    def check_params
      params.require(:check).permit(:query_id, :emails, :invert, :schedule)
    end

    def set_check
      @check = Blazer::Check.find(params[:id])
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
blazer-1.3.5 app/controllers/blazer/checks_controller.rb
blazer-1.3.4 app/controllers/blazer/checks_controller.rb
blazer-1.3.3 app/controllers/blazer/checks_controller.rb
blazer-1.3.2 app/controllers/blazer/checks_controller.rb
blazer-1.3.1 app/controllers/blazer/checks_controller.rb
blazer-1.3.0 app/controllers/blazer/checks_controller.rb