diff --git a/Gemfile b/Gemfile index 5bb06b8..edb43b1 100644 --- a/Gemfile +++ b/Gemfile @@ -3,6 +3,7 @@ ruby '3.1.2' gem 'bootsnap', require: false gem 'importmap-rails' +gem 'pagy' gem 'pg' gem 'puma' gem 'rackup' diff --git a/Gemfile.lock b/Gemfile.lock index 5ba05a6..e3eaf1a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -147,6 +147,7 @@ GEM racc (~> 1.4) nokogiri (1.16.4-x86_64-linux) racc (~> 1.4) + pagy (8.4.0) parallel (1.24.0) parser (3.3.1.0) ast (~> 2.4.1) @@ -316,6 +317,7 @@ DEPENDENCIES error_highlight htmlbeautifier importmap-rails + pagy pg puma rackup diff --git a/Procfile.dev b/Procfile.dev index e8fbe3c..b21e745 100644 --- a/Procfile.dev +++ b/Procfile.dev @@ -1,3 +1,3 @@ -web: RUBY_DEBUG_OPEN=true bundle exec -- rails server --port "${RAILS_PORT:-7500}" +web: TERMINAL_PREFIX=15 RUBY_DEBUG_OPEN=true bundle exec -- rails server --port "${RAILS_PORT:-7500}" css: BROWSERSLIST_IGNORE_OLD_DATA=true bundle exec -- rails tailwindcss:watch diff --git a/app/controllers/scores_controller.rb b/app/controllers/scores_controller.rb index 1c6ca2f..89d9e04 100644 --- a/app/controllers/scores_controller.rb +++ b/app/controllers/scores_controller.rb @@ -1,18 +1,22 @@ # ScoresController define Score and Grade interactions class ScoresController < ApplicationController + include Pagy::Backend + before_action :set_score, only: %i[show edit update destroy] # GET /scores def index - @scores = Score.all + @pagy, @scores = pagy(Score.all) + logger.info 'this is a normal message' + logger.info 'this is a super long message which should be wrapped. ' * 5 # logger.info({ one: 1, two: 2 }) # logger.info 'this is an information', { four: 4, five: 5 } # logger.debug BigDecimal('0.0003') # logger.warn 'scores are', @scores # logger.warn 'this is a warning' # logger.error 'this is an error message' - logger.info 'end of normal message' + # logger.info 'end of normal message' # logger.debug @scores # sleep 0.5 end diff --git a/app/helpers/pagy_helper.rb b/app/helpers/pagy_helper.rb new file mode 100644 index 0000000..f7518c0 --- /dev/null +++ b/app/helpers/pagy_helper.rb @@ -0,0 +1,3 @@ +module PagyHelper + include Pagy::Frontend +end diff --git a/app/views/scores/index.html.erb b/app/views/scores/index.html.erb index d02d698..e03d68b 100644 --- a/app/views/scores/index.html.erb +++ b/app/views/scores/index.html.erb @@ -8,4 +8,6 @@
<%= render @scores %>
+ + <%== pagy_nav(@pagy) %> diff --git a/config/initializers/monkey_patcher.rb b/config/initializers/monkey_patcher.rb new file mode 100644 index 0000000..f3b5e0f --- /dev/null +++ b/config/initializers/monkey_patcher.rb @@ -0,0 +1,14 @@ +return unless defined?(Rails::Server) + +puts 'MonkeyPatcher runs:' +patches = Dir.glob(Rails.root.join('lib', 'monkey_patches', '**', '*.rb')) +patches.each do |file| + puts "🐵 patching... #{Pathname.new(file).relative_path_from Rails.root}" + require file +end + +puts case patches.count + when 0 then 'No patch found' + when 1 then '1 successful patch applied' + else "#{patches.count} successful patches applied" + end diff --git a/lib/monkey_patches/rails_semantic_logger/debug_exceptions.rb b/lib/monkey_patches/rails_semantic_logger/debug_exceptions.rb new file mode 100644 index 0000000..3657a85 --- /dev/null +++ b/lib/monkey_patches/rails_semantic_logger/debug_exceptions.rb @@ -0,0 +1,14 @@ +require 'rails_semantic_logger/extensions/action_dispatch/debug_exceptions' + +module ActionDispatch + # patched class to prevent deprecated message + class DebugExceptions + private + + def log_error(_request, wrapper) + Rails.application.deprecators.silence do + ActionController::Base.logger.fatal(wrapper.exception) + end + end + end +end