Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Globalize load ActiveRecord too early (before initializers) #815

Open
runephilosof-abtion opened this issue Nov 22, 2023 · 1 comment · May be fixed by #816
Open

Globalize load ActiveRecord too early (before initializers) #815

runephilosof-abtion opened this issue Nov 22, 2023 · 1 comment · May be fixed by #816

Comments

@runephilosof-abtion
Copy link

Adding gem 'globalize' to 'Gemfile' in a new Rails app, will mean setting active_record configuration in initializers won't work.

Example

gem install rails
rails new example-globalize-rails-app --minimal
cd example-globalize-rails-app
echo "gem 'globalize'" >> Gemfile
bundle

echo "Rails.application.config.active_record.collection_cache_versioning = false" >> config/initializers/new_framework_defaults_6_0.rb
echo "raise if ActiveRecord::Base.collection_cache_versioning == true" >> config/initializers/new_framework_defaults_6_0.rb

bin/rails runner 1

Maybe the code in

globalize/lib/globalize.rb

Lines 125 to 128 in 278b9f9

ActiveRecord::Base.class_attribute :globalize_serialized_attributes, instance_writer: false
ActiveRecord::Base.globalize_serialized_attributes = {}
ActiveRecord::Base.extend(Globalize::ActiveRecord::ActMacro)
needs to be wrapped in

ActiveSupport.on_load(:active_record) do
  # your code
end

https://guides.rubyonrails.org/engines.html#configuration-hooks

runephilosof-abtion added a commit to runephilosof-abtion/globalize that referenced this issue Nov 22, 2023
Fixes globalize#815
> Globalize load ActiveRecord too early (before initializers)

Which meant that setting active_record configuration in initializers did not work.
@runephilosof-abtion runephilosof-abtion linked a pull request Nov 22, 2023 that will close this issue
@runephilosof-abtion
Copy link
Author

The same with globalize/globalize-accessors#45

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant