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

Access to controller primitives? #2682

Open
bf4 opened this issue Aug 4, 2016 · 5 comments
Open

Access to controller primitives? #2682

bf4 opened this issue Aug 4, 2016 · 5 comments

Comments

@bf4
Copy link
Contributor

bf4 commented Aug 4, 2016

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
Copy link
Contributor Author

bf4 commented Sep 20, 2016

@mshibuya any thoughts?

@mshibuya
Copy link
Member

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.

mshibuya added a commit that referenced this issue Sep 24, 2016
Closes #1325, Closes #1342, Closes #1434, Closes #2649, Refs. #2682
@bf4
Copy link
Contributor Author

bf4 commented Sep 26, 2016

@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
Copy link
Member

I've already made a solution for eager-loading, creating DSL is just so simple.
b92a4d1

@bf4
Copy link
Contributor Author

bf4 commented Sep 28, 2016

@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 #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?

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

2 participants