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.

71 lines
1.5 KiB

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