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.

78 lines
1.8 KiB

11 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
10 months ago
11 months ago
11 months ago
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. logger.info 'this is a normal message'
  8. # logger.info({ one: 1, two: 2 })
  9. # logger.info 'this is an information', { four: 4, five: 5 }
  10. # logger.debug BigDecimal('0.0003')
  11. # logger.warn 'scores are', @scores
  12. # logger.warn 'this is a warning'
  13. # logger.error 'this is an error message'
  14. logger.info 'end of normal message'
  15. # logger.debug @scores
  16. # sleep 0.5
  17. end
  18. # GET /scores/1
  19. def show; end
  20. # GET /scores/new
  21. def new
  22. @score = Score.new
  23. flash.now[:notice] = 'Unique name is mandatory!'
  24. flash.now[:alert] = 'Your book was not found'
  25. sleep 0.3
  26. end
  27. # GET /scores/1/edit
  28. def edit; end
  29. # POST /scores
  30. def create
  31. @score = Score.new(score_params)
  32. if @score.save
  33. redirect_to @score, notice: 'Score was successfully created.'
  34. else
  35. render :new, status: :unprocessable_entity
  36. end
  37. end
  38. # PATCH/PUT /scores/1
  39. def update
  40. if @score.update(score_params)
  41. redirect_to @score, notice: 'Score was successfully updated.', status: :see_other
  42. else
  43. render :edit, status: :unprocessable_entity
  44. end
  45. end
  46. # DELETE /scores/1
  47. def destroy
  48. do_an_exception
  49. @score.destroy!
  50. redirect_to scores_url, notice: 'Score was successfully destroyed.', status: :see_other
  51. end
  52. private
  53. def do_an_exception
  54. raise 'Unable to destroy this score'
  55. end
  56. # Use callbacks to share common setup or constraints between actions.
  57. def set_score
  58. @score = Score.find(params[:id])
  59. @score.grade
  60. end
  61. # Only allow a list of trusted parameters through.
  62. def score_params
  63. params.require(:score).permit(:name, :grade)
  64. end
  65. end