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.

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