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.

65 lines
1.5 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. # logger.info("#{HotConstants.boolean}")
  9. end
  10. # GET /scores/1
  11. def show; end
  12. # GET /scores/new
  13. def new
  14. @score = Score.new
  15. end
  16. # GET /scores/1/edit
  17. def edit; end
  18. # POST /scores
  19. def create
  20. @score = Score.new(score_params)
  21. if @score.save
  22. redirect_to @score, notice: 'Score was successfully created.'
  23. else
  24. render :new, status: :unprocessable_entity
  25. end
  26. end
  27. # PATCH/PUT /scores/1
  28. def update
  29. if @score.update(score_params)
  30. redirect_to @score, notice: 'Score was successfully updated.', status: :see_other
  31. else
  32. render :edit, status: :unprocessable_entity
  33. end
  34. end
  35. # DELETE /scores/1
  36. def destroy
  37. # @score.destroy!
  38. # redirect_to scores_url, notice: 'Score was successfully destroyed.', status: :see_other
  39. flash.now[:alert] = "this is 'destroyed!'"
  40. render turbo_stream: turbo_stream.replace('notification', partial: 'layouts/notification')
  41. end
  42. private
  43. # Use callbacks to share common setup or constraints between actions.
  44. def set_score
  45. @score = Score.find(params[:id])
  46. @score.grade
  47. end
  48. # Only allow a list of trusted parameters through.
  49. def score_params
  50. params.require(:score).permit(:name, :grade)
  51. end
  52. end