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.

62 lines
1.3 KiB

11 months ago
  1. # ScoresController define Score and Grade interactions
  2. class ScoresController < ApplicationController
  3. before_action :set_score, only: %i[show edit update destroy]
  4. # GET /scores
  5. def index
  6. @scores = Score.all
  7. puts 'hello'
  8. end
  9. # GET /scores/1
  10. def show
  11. puts "show #{params}"
  12. end
  13. # GET /scores/new
  14. def new
  15. @score = Score.new
  16. end
  17. # GET /scores/1/edit
  18. def edit; end
  19. # POST /scores
  20. def create
  21. @score = Score.new(score_params)
  22. if @score.save
  23. redirect_to @score, notice: 'Score was successfully created.'
  24. else
  25. render :new, status: :unprocessable_entity
  26. end
  27. end
  28. # PATCH/PUT /scores/1
  29. def update
  30. if @score.update(score_params)
  31. redirect_to @score, notice: 'Score was successfully updated.', status: :see_other
  32. else
  33. render :edit, status: :unprocessable_entity
  34. end
  35. end
  36. # DELETE /scores/1
  37. def destroy
  38. @score.destroy!
  39. redirect_to scores_url, notice: 'Score was successfully destroyed.', status: :see_other
  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