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

11 months ago
11 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 an information', { 'one': 1, 'two': 2 }
  8. logger.info 'this is an object', BigDecimal('0.0001')
  9. # logger.warn 'this is a warning'
  10. # logger.error 'this is an error'
  11. # logger.debug 'this is a debug message'
  12. # logger.fatal 'FATAL'
  13. logger.debug 'score are', @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