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.

61 lines
1.3 KiB

11 months ago
11 months ago
11 months ago
5 months ago
11 months ago
  1. # ScoresController define Score and Grade interactions
  2. class ScoresController < ApplicationController
  3. include Pagy::Backend
  4. before_action :set_score, only: %i[show edit update destroy]
  5. # GET /scores
  6. def index
  7. @pagy, @scores = pagy(Score.all)
  8. end
  9. # GET /scores/1
  10. def show; end
  11. # GET /scores/new
  12. def new
  13. @score = Score.new
  14. end
  15. # GET /scores/1/edit
  16. def edit; end
  17. # POST /scores
  18. def create
  19. @score = Score.new(score_params)
  20. if @score.save
  21. redirect_to @score, notice: 'Score was successfully created.'
  22. else
  23. render :new, status: :unprocessable_entity
  24. end
  25. end
  26. # PATCH/PUT /scores/1
  27. def update
  28. if @score.update(score_params)
  29. redirect_to @score, notice: 'Score was successfully updated.', status: :see_other
  30. else
  31. render :edit, status: :unprocessable_entity
  32. end
  33. end
  34. # DELETE /scores/1
  35. def destroy
  36. @score.destroy!
  37. redirect_to scores_url, notice: 'Score was successfully destroyed.', status: :see_other
  38. end
  39. private
  40. # Use callbacks to share common setup or constraints between actions.
  41. def set_score
  42. @score = Score.find(params[:id])
  43. @score.grade
  44. end
  45. # Only allow a list of trusted parameters through.
  46. def score_params
  47. params.require(:score).permit(:name, :grade)
  48. end
  49. end