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.

76 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
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; end
  20. # GET /scores/new
  21. def new
  22. @score = Score.new
  23. sleep 0.3
  24. end
  25. # GET /scores/1/edit
  26. def edit; end
  27. # POST /scores
  28. def create
  29. @score = Score.new(score_params)
  30. if @score.save
  31. redirect_to @score, notice: 'Score was successfully created.'
  32. else
  33. render :new, status: :unprocessable_entity
  34. end
  35. end
  36. # PATCH/PUT /scores/1
  37. def update
  38. if @score.update(score_params)
  39. redirect_to @score, notice: 'Score was successfully updated.', status: :see_other
  40. else
  41. render :edit, status: :unprocessable_entity
  42. end
  43. end
  44. # DELETE /scores/1
  45. def destroy
  46. do_an_exception
  47. @score.destroy!
  48. redirect_to scores_url, notice: 'Score was successfully destroyed.', status: :see_other
  49. end
  50. private
  51. def do_an_exception
  52. raise 'Unable to destroy this score'
  53. end
  54. # Use callbacks to share common setup or constraints between actions.
  55. def set_score
  56. @score = Score.find(params[:id])
  57. @score.grade
  58. end
  59. # Only allow a list of trusted parameters through.
  60. def score_params
  61. params.require(:score).permit(:name, :grade)
  62. end
  63. end