railsadminteam / rails_admin

RailsAdmin is a Rails engine that provides an easy-to-use interface for managing your data
MIT License
7.88k stars 2.25k forks source link

Access to controller primitives? #2682

Open bf4 opened 8 years ago

bf4 commented 8 years ago

If this exists, I can't find it, but is there a place where, either in an action or in a configuration, that I can access the controller class or instance? It'd make working with RailsAdmin a lot easier if I had access to what I'm calling the primitives-- the things every Rails dev knows, even if they can't figure something out using the RailsAdmin DSL.

When I make a custom action I controller the proc that is evaluated in the control. Would be nice if the built-in controller proc's called out to some method hook I could use.

I know there's a MainController and I know there are actions, but I don't know what to modify them per generated controller or controller action.

This would be particularly useful for fixing N+1 queries.

There's a lot of people monkeypatching RailsAdmin to be able to do these kinds of things :(

I'm happy to help, but thus far my efforts have failed. Any guidance is appreciated.

Related:

Possibly Related:

bf4 commented 8 years ago

@mshibuya any thoughts?

mshibuya commented 8 years ago

This topic appears to be too broad...

Accessing the controller instance:

Controller actions are instance_evaled in RailsAdmin::MainController, so self in custom action proc references the controller instance. Is this the answer you're looking for?

Eager loading, Overriding search, Unscoping

These features are to be implemented through specifically-designed RailsAdmin-ish DSL, not monkey-patching. If you have new DSL idea, please feel free to open PR and we'll discuss it there.

bf4 commented 8 years ago

@mshibuya

Thanks for writing back!

I am specifically not referring to custom actions, but to a scenario where I want to, e.g. add eager loading to a model in an action. I shouldn't need to wait for RailsAdmin to promote that to a DSL, right? Right now, I think the ways to do it are both hacks:

  1. Use a callback in applicaitoncontroller that checks if the current controller is a rails admin controller, and do something if so,
  2. take advantage of 'render' blogs, like referenced in the wiki http://glaucocustodio.com/2013/11/28/conditional-fields-in-rails-admin/

This lack of access to what I'm calling 'controller primitives' was also a problem for me in a previous project that used ActiveAdmin. The DSL is great, but exposing a 'controller do' or 'super do' would make a lot of my struggles with customizing our admin easier. I know Rails pretty well, and maybe that's part of my problem :)

Does that help? Or any of the referenced issues?

mshibuya commented 8 years ago

I've already made a solution for eager-loading, creating DSL is just so simple. https://github.com/sferik/rails_admin/commit/b92a4d1a30b706d08df2aee4d0a59dad698a0552

bf4 commented 8 years ago

@mshibuya but, unless I'm misunderstanding, the only way for me to make the change in that ref is by a PR to the repo, whereas what I'm interested in is not needing to do that. I think that with the changeset in https://github.com/sferik/rails_admin/pull/2649 I could have used a hack to access the controller by taking advantage of 'render'.

Or, more directly, how could I have gotten the behavior of b92a4d1 without a PR to rails_admin?