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.

66 lines
1.4 KiB

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