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.

73 lines
1.6 KiB

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