checks_controller.rb 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. # use creator_id instead of creator
  14. # since we setup association without checking if column exists
  15. @check.creator = blazer_user if @check.respond_to?(:creator_id=)
  16. if @check.save
  17. redirect_to run_check_path(@check)
  18. else
  19. render :new
  20. end
  21. end
  22. def update
  23. if @check.update(check_params)
  24. redirect_to run_check_path(@check)
  25. else
  26. render :edit
  27. end
  28. end
  29. def destroy
  30. @check.destroy
  31. redirect_to checks_path
  32. end
  33. def run
  34. @query = @check.query
  35. end
  36. private
  37. def check_params
  38. params.require(:check).permit(:query_id, :emails, :invert, :schedule)
  39. end
  40. def set_check
  41. @check = Blazer::Check.find(params[:id])
  42. end
  43. end
  44. end