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.

67 lines
1.5 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.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. @score.destroy!
  44. redirect_to scores_url, notice: 'Score was successfully destroyed.', status: :see_other
  45. end
  46. private
  47. # Use callbacks to share common setup or constraints between actions.
  48. def set_score
  49. @score = Score.find(params[:id])
  50. @score.grade
  51. end
  52. # Only allow a list of trusted parameters through.
  53. def score_params
  54. params.require(:score).permit(:name, :grade)
  55. end
  56. end