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.6 KiB

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