You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
1.7 KiB

11 months ago
10 months ago
10 months ago
10 months ago
11 months ago
10 months ago
11 months ago
11 months ago
11 months ago
  1. # ScoresController define Score and Grade interactions
  2. class ScoresController < ApplicationController
  3. before_action :set_score, only: %i[show edit update destroy]
  4. # GET /scores
  5. def index
  6. @scores = Score.all
  7. logger.debug 'this is a debug message'
  8. logger.debug({ 'one': 1, 'two': 2 })
  9. logger.info 'this is an information', { 'four': 4, 'five': 5 }
  10. logger.info 'this is an object', BigDecimal('0.0001')
  11. logger.warn 'this is a warning'
  12. logger.error 'this is an error', BigDecimal('0.0002')
  13. logger.debug BigDecimal('0.0003')
  14. logger.debug 'scores are', @scores
  15. logger.debug @scores
  16. end
  17. # GET /scores/1
  18. def show; end
  19. # GET /scores/new
  20. def new
  21. @score = Score.new
  22. end
  23. # GET /scores/1/edit
  24. def edit; end
  25. # POST /scores
  26. def create
  27. @score = Score.new(score_params)
  28. if @score.save
  29. redirect_to @score, notice: 'Score was successfully created.'
  30. else
  31. render :new, status: :unprocessable_entity
  32. end
  33. end
  34. # PATCH/PUT /scores/1
  35. def update
  36. if @score.update(score_params)
  37. redirect_to @score, notice: 'Score was successfully updated.', status: :see_other
  38. else
  39. render :edit, status: :unprocessable_entity
  40. end
  41. end
  42. # DELETE /scores/1
  43. def destroy
  44. do_an_exception
  45. @score.destroy!
  46. redirect_to scores_url, notice: 'Score was successfully destroyed.', status: :see_other
  47. end
  48. private
  49. def do_an_exception
  50. raise 'Unable to destroy this score'
  51. end
  52. # Use callbacks to share common setup or constraints between actions.
  53. def set_score
  54. @score = Score.find(params[:id])
  55. @score.grade
  56. end
  57. # Only allow a list of trusted parameters through.
  58. def score_params
  59. params.require(:score).permit(:name, :grade)
  60. end
  61. end