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.

52 lines
1.2 KiB

11 months ago
11 months ago
3 months ago
11 months ago
5 months ago
11 months ago
5 months ago
11 months ago
3 months ago
3 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. def index
  6. logger.info 'index called A'
  7. @q = Score.all.ransack(q_params)
  8. @pagy, @scores = pagy(@q.result)
  9. end
  10. def show; end
  11. def new
  12. @score = Score.new
  13. end
  14. def edit; end
  15. def create
  16. @score = Score.new(score_params)
  17. if @score.save
  18. redirect_to @score, notice: 'Score was successfully created.'
  19. else
  20. render :new, status: :unprocessable_entity
  21. end
  22. end
  23. def update
  24. if @score.update(score_params)
  25. redirect_to @score, notice: 'Score was successfully updated.', status: :see_other
  26. else
  27. render :edit, status: :unprocessable_entity
  28. end
  29. end
  30. def destroy
  31. # @score.destroy!
  32. # redirect_to scores_url, notice: 'Score was successfully destroyed.', status: :see_other
  33. flash.now[:alert] = "this is 'destroyed!'"
  34. render turbo_stream: turbo_stream.replace('notification', partial: 'layouts/notification')
  35. end
  36. private
  37. def set_score = @score = Score.find(params[:id])
  38. def score_params = params.require(:score).permit(:name, :grade)
  39. def q_params = params.fetch(:q, {}).permit!
  40. end