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.

68 lines
1.5 KiB

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
  13. end
  14. # GET /scores/1
  15. def show
  16. puts "show #{params}"
  17. 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. raise 'Unable to destroy this score'
  44. @score.destroy!
  45. redirect_to scores_url, notice: 'Score was successfully destroyed.', status: :see_other
  46. end
  47. private
  48. # Use callbacks to share common setup or constraints between actions.
  49. def set_score
  50. @score = Score.find(params[:id])
  51. @score.grade
  52. end
  53. # Only allow a list of trusted parameters through.
  54. def score_params
  55. params.require(:score).permit(:name, :grade)
  56. end
  57. end