Two cookie_serializer initializers
There are two contradicting cookie_serializers initialized:
$ rg 'Rails.application.config.action_dispatch.cookies_serializer'
config/initializers/cookies_serializer.rb
3:Rails.application.config.action_dispatch.cookies_serializer = :marshal
config/initializers/hybrid_cookies_serializer.rb
3:Rails.application.config.action_dispatch.cookies_serializer = :hybrid
:marshal was the default before 4.1, since then a JSON serializer is used. :hybrid accepts :marshal and helps with migrating to :json. See Rails' upgrading guide for more information: https://guides.rubyonrails.org/upgrading_ruby_on_rails.html#cookies-serializer
I think we should move "config/initializers/hybrid_cookies_serializer.rb" to "config/initializers/cookies_serializer.rb", overwritting the current version with :marshal
You propose consolidating these two configurations into a single initializer (config/initializers/cookies_serializer.rb) and setting the serializer to :hybrid. This is a sensible approach, as it simplifies the configuration and aligns with Rails' recommendation for migration.
Here’s how you can proceed:
Move the Configuration:
Delete the config/initializers/hybrid_cookies_serializer.rb file. Update config/initializers/cookies_serializer.rb to use :hybrid instead of :marshal. Updated cookies_serializer.rb Content:
ruby
config/initializers/cookies_serializer.rb
Rails.application.config.action_dispatch.cookies_serializer = :hybrid
Document the Change:
Add a comment in the initializer to explain why :hybrid is used and reference the Rails upgrading guide. Inform the team about this change so they know the system now supports both old :marshal and new :json cookies. Test Thoroughly:
Verify that the application can read both :marshal and :json serialized cookies. Ensure new cookies are being serialized as JSON. By consolidating the configuration and migrating toward :json using the :hybrid serializer, you adhere to Rails' best practices while minimizing potential issues.