Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • A administrate
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 96
    • Issues 96
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 32
    • Merge requests 32
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • thoughtbot, inc.
  • administrate
  • Merge requests
  • !1299

Fix routes generator for Rails 6 zeitwerk autoloader

  • Review changes

  • Download
  • Email patches
  • Plain diff
Closed Administrator requested to merge github/fork/excid3/zeitwerk-fix into master Feb 28, 2019
  • Overview 2
  • Commits 1
  • Pipelines 0
  • Changes 1

Created by: excid3

The classic autoloader worked fine for looking up all models when running the routes generator.

Rails 6 introduces zeitwerk as the default autoloader and it does not load all the models until needed.

I did some inspection to see why Administrate was only loading only my Devise model and nothing else.

> ActiveRecord::Base.descendants
=> [ApplicationRecord(abstract), User (call 'User.connection' to establish a connection)]
> Rails.autoloaders.main.eager_load
=> true
> ActiveRecord::Base.descendants
=> [ApplicationRecord(abstract), User (call 'User.connection' to establish a connection), Announcement (call 'Announcement.connection' to establish a connection), Notification (call 'Notification.connection' to establish a connection), Service (call 'Service.connection' to establish a connection)]

After the eager load, all the models are available. In the old / classic autoloader from Rails 5 and earlier, you'd get the second set of results the first time.

This fixes it so Rails 6 will generate all the models like it used to.

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/excid3/zeitwerk-fix