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.

82 lines
2.0 KiB

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