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.

77 lines
1.7 KiB

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