-
-
Notifications
You must be signed in to change notification settings - Fork 592
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Defer loading of ActiveRecord to avoid config issues
If FriendlyId references `ActiveRecord::Base` while it is loading as part of a Rails application, it triggers the `on_load` event for ActiveRecord, which as part of the loading process sets the current configuration values of ActiveRecord. If any initializers try to influence that configuration (e.g. changing defaults in `new_framework_defaults.rb` for an app that's been upgraded), these changes will have no effect because the configuration has already been set in place. To avoid this, we need to avoid triggering the `on_load` event by wrapping the reference to `ActiveRecord::Base` in an initializer block. The simplest way of doing this is with a `Railtie`, which will be automatically loaded if FriendlyId is required as part of Rails. Fixes #823
- Loading branch information
Showing
4 changed files
with
17 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module FriendlyId | ||
class Railtie < Rails::Railtie | ||
initializer 'friendly_id.setup' do | ||
ActiveSupport.on_load(:active_record) do | ||
FriendlyId.mark_as_unfriendly(ActiveRecord::Base) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters