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.

64 lines
1.4 KiB

9 months ago
9 months ago
9 months ago
3 months ago
9 months ago
3 months ago
9 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. flash.now[:alert] = "this is 'destroyed!'"
  39. render turbo_stream: turbo_stream.replace('notification', partial: 'layouts/notification')
  40. end
  41. private
  42. # Use callbacks to share common setup or constraints between actions.
  43. def set_score
  44. @score = Score.find(params[:id])
  45. @score.grade
  46. end
  47. # Only allow a list of trusted parameters through.
  48. def score_params
  49. params.require(:score).permit(:name, :grade)
  50. end
  51. end