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.

72 lines
1.6 KiB

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