Activeadmin: Don't register ActiveAdmin::Comment as Comments

Created on 18 Jul 2011  路  34Comments  路  Source: activeadmin/activeadmin

It can be confusing to not be able to register your own model named Comment because of the default comments that come with Active Admin. We should register ActiveAdmin::Comments as something other than Comments.

feature

Most helpful comment

I know this is very old, but apparently I missed the ability to change the registered names for comments using config.comments_registration_name = 'AdminComment' (posting this comment in case someone else is digging around looking for the solution).

All 34 comments

+1

+1

Is there a workaround?

Almost every site with user interaction has comments. This issue is still open, really stupid and because of it I'll have to create own admin panel >_<

P.S. Thats not a feature. Thats a BUG!

Do you have an estimate of when this bug is going to be fixed?

@naquad - There's nothing holding you back from registering your comments with another name. I don't see how this could force you to create your own admin panel?

@mitran it will be updated in the 0.4.0 release. Should be out next week.

What happened with this? It's definitely still an issue in 0.4.0

Still an issue in 0.4.3 you mean.

still issue with 0.5.0

Hmm seems like this is still an issue with 0.6

+1

@tkhr what exactly is the problem? I can do this without any issue:

ActiveAdmin.register ActiveAdmin::Comment, as: 'FooBar'

@Daxter i cant do something like

ActiveAdmin.register Comment, :as => "BlogComment" do
end

:(

ref: https://github.com/gregbell/active_admin/issues/64#issuecomment-1208910

I get an error

superclass mismatch for class CommentsController

@Daxter: This is the error that occurs if I do what you suggest鈥攔e-registering ActiveAdmin::Comment under a different name鈥攐r try to register Comment with ActiveAdmin without giving a different name to register it as:

/path/to/gems/activeadmin-0.6.0/lib/active_admin/resource_collection.rb:82:in `ensure_resource_classes_match!': Tried to register ActiveAdmin::Comment as Comment but already registered to Comment (ActiveAdmin::ResourceMismatchError)

Basically, it doesn't register the new name, still tries to register as Comment and fails (keeping the Rails server from starting) since Comment is already registered.

Registering Comment under a different name does work for me with 0.6.0 (I don't think it did with 0.5.1) unlike what @tkhr described, e.g.

ActiveAdmin.register Comment, as: "UserComment" do
  index do
    selectable_column
    column :id
    column :commentable
    column :user
    column :body
    column :created_at
    default_actions
  end
end

but this workaround shouldn't be necessary by default, IMO, since Comment is such a common class name for a Rails application to have. ActiveAdmin's comments should be registered under a different name, and that seems to need to be done from within ActiveAdmin.

Belay my last comment. Here's what's happening in my app's routing with admin comments enabled and Comment registered as UserComment:

(snip)
batch_action_admin_user_comments POST   /admin/user_comments/batch_action(.:format)    admin/user_comments#batch_action
             admin_user_comments GET    /admin/user_comments(.:format)                 admin/user_comments#index
                                 POST   /admin/user_comments(.:format)                 admin/user_comments#create
          new_admin_user_comment GET    /admin/user_comments/new(.:format)             admin/user_comments#new
         edit_admin_user_comment GET    /admin/user_comments/:id/edit(.:format)        admin/user_comments#edit
              admin_user_comment GET    /admin/user_comments/:id(.:format)             admin/user_comments#show
                                 PUT    /admin/user_comments/:id(.:format)             admin/user_comments#update
                                 DELETE /admin/user_comments/:id(.:format)             admin/user_comments#destroy
(snip)
     batch_action_admin_comments POST   /admin/comments/batch_action(.:format)         admin/comments#batch_action
                  admin_comments GET    /admin/comments(.:format)                      admin/comments#index
                                 POST   /admin/comments(.:format)                      admin/comments#create
                   admin_comment GET    /admin/comments/:id(.:format)                  admin/comments#show
           batch_action_comments POST   /comments/batch_action(.:format)               comments#batch_action
                        comments GET    /comments(.:format)                            comments#index
                                 POST   /comments(.:format)                            comments#create
                                 GET    /comments/:id(.:format)                        comments#show

Routes for the admin comments are being mapped both to the admin namespace and to the Rails app's root namespace, which is the same sort of thing that is happening in #2049 (which is why I have ActiveAdmin's routes at the bottom of my routing.rb for the time being). That may be what's causing the exception @tkhr is seeing, which I am also seeing when I run rake or rake spec by itself and during Travis-CI builds, as well as causing my normal CommentsController to no longer function properly even though the server starts normally.

+1 Thanks for the change to AdminComment. I ran into this same collision issue with the acts_as_commentable_with_threading gem.

@mikeatlas as of #2113 it's set back to use Comment instead of AdminComment, except now the registration name is configurable.

@Daxter Thanks, but your default name should really be AdminComment as comments are turned on by default in the configuration, which means more people like myself will have to track down a collision first in order to find the configurable name for AA comments. I just pulled in the AA gem today and it wasn't even apparent to me from the outset that AA had a comment feature which was colliding; my error messages were just saying that AbstractController::ActionNotFound for my existing CommentsController#action methods.

IMO we should be using Comment instead of AdminComment

The issue of clashing controllers is a larger problem.

# what we do now
eval "class ::#{config.controller_name} < ActiveAdmin::ResourceController; end"
# what we should be doing
Object.const_set config.controller_name, Class.new(ActiveAdmin::ResourceController)

That way you'd actually get an error when registering CommentsController if it's a constant that already exists.

It's big problem that ActiveAdmin declares a top-level controller called CommentsController, and the error it generates is cryptic as well.
All the ActiveAdmin controllers should be namespaced under Admin no avoid any collisions.

/admin/comments => ActiveAdmin::CommentsController

Just upgraded to AA 0.6 but had to downgrade to 0.5 for this same reason.

+1, have downgraded from 0.6.0 to 0.5.1 to avoid this

app/controllers/comments_controller.rb:1:in `<top (required)>': superclass mismatch for class CommentsController (TypeError)

:+1:, downgrading... this is why we have namespaces :)

It would be really awesome if this issue, which has been outstanding for 3+ years, could be resolved once and for all. It seems ridiculous that it can't be changed to AdminComment or ActiveAdminComment so we can all get on with things.

@renaebair #2113 made the name configurable. Is that not good enough?

@seanlinsley yup, actually that worked! Didn't see #2113 referenced above, my bad! I was looking through 3-4 other "issues" on this, each of them were closed and linked to other issue #'s and I didn't follow through all the way to find #2113. In short, yes, #2113 solves my issue ^^

Yeah, as many tickets there are, it can be difficult to internalize the full history. Glad to hear #2113 works for you :cat:

I have it running under acts_as_tenant, great that it's loading active_admin_comment instead of the old comments table, but if I add a model and for the table and add the tenant tag, it doesn't respond to it as being loaded already. At the moment all tenants can see each others comments if they go to /admin/comments. Any ideas?

@simonhutchings please make a new ticket with as many details as possible so we can try and figure out the issue.

I know this is very old, but apparently I missed the ability to change the registered names for comments using config.comments_registration_name = 'AdminComment' (posting this comment in case someone else is digging around looking for the solution).

@abrambailey +1 thank you! Saved me a lot of time. Cheers!

How stupid it is!
Why not make config.comments_registration_name = 'AdminComment' as default?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tobyhede picture tobyhede  路  31Comments

ghost picture ghost  路  34Comments

ghost picture ghost  路  63Comments

seanlinsley picture seanlinsley  路  31Comments

rainchen picture rainchen  路  32Comments