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.

51 lines
1.2 KiB

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