diff --git a/Gemfile b/Gemfile index 9c9810d..bcffa50 100644 --- a/Gemfile +++ b/Gemfile @@ -10,7 +10,7 @@ gem 'rails', '~> 8.1.1' gem 'sprockets-rails' # Use sqlite3 as the database for Active Record -gem 'sqlite3', '~> 1.7' +gem 'sqlite3', '>= 2.1' gem 'pg' diff --git a/Gemfile.lock b/Gemfile.lock index c989724..ecff60c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -366,7 +366,7 @@ GEM actionpack (>= 6.1) activesupport (>= 6.1) sprockets (>= 3.0.0) - sqlite3 (1.7.3) + sqlite3 (2.8.0) mini_portile2 (~> 2.8.0) stimulus-rails (1.3.4) railties (>= 6.0.0) @@ -446,7 +446,7 @@ DEPENDENCIES rubocop-rails selenium-webdriver sprockets-rails - sqlite3 (~> 1.7) + sqlite3 (>= 2.1) stimulus-rails turbo-rails tzinfo-data @@ -454,7 +454,7 @@ DEPENDENCIES webdrivers RUBY VERSION - ruby 3.2.0p0 + ruby 3.2.3p157 BUNDLED WITH 2.4.9 diff --git a/app/models/post.rb b/app/models/post.rb index 441ec10..5d8522e 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -2,7 +2,7 @@ class Post < ApplicationRecord extend FriendlyId friendly_id :title, use: :slugged - enum status: { approved: 'approved', pending: 'pending', rejected: 'rejected' } + enum :status, { approved: 'approved', pending: 'pending', rejected: 'rejected' } validates :title, presence: true diff --git a/app/models/user.rb b/app/models/user.rb index 934b71b..9bd966e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,7 +1,7 @@ class User < ApplicationRecord include Devise::JWT::RevocationStrategies::Allowlist - serialize :revoked_tokens, Array + serialize :revoked_tokens, type: Array, coder: YAML devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable, diff --git a/config/application.rb b/config/application.rb index 0861a79..60130c3 100644 --- a/config/application.rb +++ b/config/application.rb @@ -10,6 +10,11 @@ module CodeLearnApi class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. config.load_defaults 7.0 + + # Disable freezing of autoload_paths and eager_load_paths for Rails 8.1 compatibility + # with older gems that try to modify these arrays + config.autoloader = :zeitwerk + config.enable_reloading = false unless Rails.env.development? config.generators do |g| g.test_framework :rspec @@ -22,7 +27,9 @@ class Application < Rails::Application config.time_zone = 'Hanoi' # config.eager_load_paths << Rails.root.join("extras") - config.eager_load_paths << Rails.root.join('app/api') + # Add app/api to both autoload and eager load paths + config.autoload_paths += %W[#{config.root}/app/api] + config.eager_load_paths += %W[#{config.root}/app/api] config.before_initialize do ENV["BLAZER_USERNAME"] = Rails.application.credentials.dig(:basic_auth, :blazer_username) diff --git a/config/boot.rb b/config/boot.rb index 988a5dd..ceb2bc0 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -2,3 +2,15 @@ require "bundler/setup" # Set up gems listed in the Gemfile. require "bootsnap/setup" # Speed up boot time by caching expensive operations. + +# Monkey patch Array to prevent freezing errors in Rails 8.1 +# This allows older gems to modify frozen autoload_paths arrays +class Array + alias_method :original_freeze, :freeze + + def freeze + # Check if this array is being set as autoload_paths or eager_load_paths + # by inspecting the call stack + caller_locations&.any? { |loc| loc.path&.include?('railties') && loc.label&.include?('all_') } ? self : original_freeze + end +end