checks_controller.rb 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. module Blazer
  2. class ChecksController < BaseController
  3. before_action :set_check, only: [:edit, :update, :destroy, :run]
  4. def index
  5. @checks = Blazer::Check.joins(:query).includes(:query).order("state, blazer_queries.name, blazer_checks.id").to_a
  6. @checks.select! { |c| "#{c.query.name} #{c.emails}".downcase.include?(params[:q]) } if params[:q]
  7. end
  8. def new
  9. @check = Blazer::Check.new
  10. end
  11. def create
  12. @check = Blazer::Check.new(check_params)
  13. if @check.save
  14. redirect_to run_check_path(@check)
  15. else
  16. render :new
  17. end
  18. end
  19. def update
  20. if @check.update(check_params)
  21. redirect_to run_check_path(@check)
  22. else
  23. render :edit
  24. end
  25. end
  26. def destroy
  27. @check.destroy
  28. redirect_to checks_path
  29. end
  30. def run
  31. @query = @check.query
  32. end
  33. private
  34. def check_params
  35. params.require(:check).permit(:query_id, :emails, :invert)
  36. end
  37. def set_check
  38. @check = Blazer::Check.find(params[:id])
  39. end
  40. end
  41. end