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

superclass mismatch for class DashboardController in development #8575

Open
vfonic opened this issue Dec 12, 2024 · 0 comments
Open

superclass mismatch for class DashboardController in development #8575

vfonic opened this issue Dec 12, 2024 · 0 comments

Comments

@vfonic
Copy link
Contributor

vfonic commented Dec 12, 2024

In new Rails 8 app, ActiveAdmin 4 (beta 15 or master), after raising an error such as NoMethodError in some AA resource class, triggers superclass mismatch for class DashboardController. The only mitigation is to restart the server.
The error needs to be raised at the "root" of the class/resource, such as:

ActiveAdmin.register Post do
  raise 'asd'
end

Here are the steps to repro:

rails new superclass_admin 
cd superclass_admin
bundle install
rails db:prepare
rails g scaffold post title:string
bundle add activeadmin --version "4.0.0.beta15"
rails g active_admin:install --skip-users
rails db:migrate
rails g active_admin:resource Post
rails s

After this, open app/admin/posts.rb and change permit_params :title to aaapermit_param :title.
You get undefined method aaapermit_params' for an instance of ActiveAdmin::ResourceDSLas expected. Now changeaaapermit_paramsback topermit_params` and reload the page.

Expected behavior

The page should reload.

Actual behavior

superclass mismatch for class DashboardController

A quick patch that I discovered is to add this code to the gem:

# lib/active_admin/namespace.rb

    # TODO: replace `eval` with `Class.new`
    def register_resource_controller(config)
+     name_parts = config.controller_name.split('::')
+     const_name = name_parts.last
+     if Admin.const_defined?(const_name)
+       Admin.send(:remove_const, const_name)
+     end
      eval "class ::#{config.controller_name} < ActiveAdmin::ResourceController; end"
      config.controller.active_admin_config = config
    end
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

No branches or pull requests

1 participant